Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1239329

Re: [PATCH v4 2/4] mm, proc: account for shmem swap in /proc/pid/smaps

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH v4 2/4] mm, proc: account for shmem swap in /proc/pid/smaps
Date 2015-10-05 10:00 +0200
Message-ID <qg8QG-14p-7@gated-at.bofh.it> (permalink)
References <qf8J4-4MS-19@gated-at.bofh.it> <qf8J6-4MS-65@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Oct 02, 2015 at 03:35:49PM +0200, Vlastimil Babka wrote:
> +static unsigned long smaps_shmem_swap(struct vm_area_struct *vma)
> +{
> +	struct inode *inode;
> +	unsigned long swapped;
> +	pgoff_t start, end;
> +
> +	if (!vma->vm_file)
> +		return 0;
> +
> +	inode = file_inode(vma->vm_file);
> +
> +	if (!shmem_mapping(inode->i_mapping))
> +		return 0;
> +
> +	/*
> +	 * The easier cases are when the shmem object has nothing in swap, or
> +	 * we have the whole object mapped. Then we can simply use the stats
> +	 * that are already tracked by shmem.
> +	 */
> +	swapped = shmem_swap_usage(inode);
> +
> +	if (swapped == 0)
> +		return 0;
> +
> +	if (vma->vm_end - vma->vm_start >= inode->i_size)
> +		return swapped;
> +
> +	/*
> +	 * Here we have to inspect individual pages in our mapped range to
> +	 * determine how much of them are swapped out. Thanks to RCU, we don't
> +	 * need i_mutex to protect against truncating or hole punching.
> +	 */

At the very least put in an assertion that we hold the RCU read lock,
otherwise RCU doesn't guarantee anything and its not obvious it is held
here.

> +	start = linear_page_index(vma, vma->vm_start);
> +	end = linear_page_index(vma, vma->vm_end);
> +
> +	return shmem_partial_swap_usage(inode->i_mapping, start, end);
> +}

> + * Determine (in bytes) how much of the whole shmem object is swapped out.
> + */
> +unsigned long shmem_swap_usage(struct inode *inode)
> +{
> +	struct shmem_inode_info *info = SHMEM_I(inode);
> +	unsigned long swapped;
> +
> +	/* Mostly an overkill, but it's not atomic64_t */

Yeah, that don't make any kind of sense.

> +	spin_lock(&info->lock);
> +	swapped = info->swapped;
> +	spin_unlock(&info->lock);
> +
> +	return swapped << PAGE_SHIFT;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/4] enhance shmem process and swap accounting Vlastimil Babka <vbabka@suse.cz> - 2015-10-02 15:40 +0200
  [PATCH v4 2/4] mm, proc: account for shmem swap in /proc/pid/smaps Vlastimil Babka <vbabka@suse.cz> - 2015-10-02 15:40 +0200
    Re: [PATCH v4 2/4] mm, proc: account for shmem swap in  /proc/pid/smaps Jerome Marchand <jmarchan@redhat.com> - 2015-10-02 17:10 +0200
    Re: [PATCH v4 2/4] mm, proc: account for shmem swap in  /proc/pid/smaps Michal Hocko <mhocko@kernel.org> - 2015-10-02 17:30 +0200
    Re: [PATCH v4 2/4] mm, proc: account for shmem swap in  /proc/pid/smaps Andrew Morton <akpm@linux-foundation.org> - 2015-10-03 00:40 +0200
    Re: [PATCH v4 2/4] mm, proc: account for shmem swap in  /proc/pid/smaps Hugh Dickins <hughd@google.com> - 2015-10-05 05:10 +0200
    Re: [PATCH v4 2/4] mm, proc: account for shmem swap in  /proc/pid/smaps Peter Zijlstra <peterz@infradead.org> - 2015-10-05 10:00 +0200

csiph-web