From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com [209.85.217.180]) by kanga.kvack.org (Postfix) with ESMTP id 07A54900049 for ; Wed, 11 Mar 2015 11:03:23 -0400 (EDT) Received: by lbvp9 with SMTP id p9so9469433lbv.8 for ; Wed, 11 Mar 2015 08:03:22 -0700 (PDT) Received: from forward-corp1g.mail.yandex.net (forward-corp1g.mail.yandex.net. [2a02:6b8:0:1402::10]) by mx.google.com with ESMTPS id ai6si2459407lbc.147.2015.03.11.08.03.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 08:03:18 -0700 (PDT) Message-ID: <5500592D.4090309@yandex-team.ru> Date: Wed, 11 Mar 2015 18:03:09 +0300 From: Konstantin Khlebnikov MIME-Version: 1.0 Subject: Re: [PATCH 2/4] mm, procfs: account for shmem swap in /proc/pid/smaps References: <1424958666-18241-1-git-send-email-vbabka@suse.cz> <1424958666-18241-3-git-send-email-vbabka@suse.cz> In-Reply-To: Content-Type: multipart/mixed; boundary="------------080407040304000000060205" Sender: owner-linux-mm@kvack.org List-ID: To: Konstantin Khlebnikov , Vlastimil Babka Cc: "linux-mm@kvack.org" , Jerome Marchand , Linux Kernel Mailing List , Andrew Morton , linux-doc@vger.kernel.org, Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Cyrill Gorcunov , Randy Dunlap , linux-s390@vger.kernel.org, Martin Schwidefsky , Heiko Carstens , Peter Zijlstra , Paul Mackerras , Arnaldo Carvalho de Melo , Oleg Nesterov This is a multi-part message in MIME format. --------------080407040304000000060205 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 11.03.2015 15:30, Konstantin Khlebnikov wrote: > On Thu, Feb 26, 2015 at 4:51 PM, Vlastimil Babka wrote: >> Currently, /proc/pid/smaps will always show "Swap: 0 kB" for shmem-backed >> mappings, even if the mapped portion does contain pages that were swapped out. >> This is because unlike private anonymous mappings, shmem does not change pte >> to swap entry, but pte_none when swapping the page out. In the smaps page >> walk, such page thus looks like it was never faulted in. > > Maybe just add count of swap entries allocated by mapped shmem into > swap usage of this vma? That's isn't exactly correct for partially > mapped shmem but this is something weird anyway. Something like that (see patch in attachment) > >> >> This patch changes smaps_pte_entry() to determine the swap status for such >> pte_none entries for shmem mappings, similarly to how mincore_page() does it. >> Swapped out pages are thus accounted for. >> >> The accounting is arguably still not as precise as for private anonymous >> mappings, since now we will count also pages that the process in question never >> accessed, but only another process populated them and then let them become >> swapped out. I believe it is still less confusing and subtle than not showing >> any swap usage by shmem mappings at all. Also, swapped out pages only becomee a >> performance issue for future accesses, and we cannot predict those for neither >> kind of mapping. >> >> Signed-off-by: Vlastimil Babka >> --- >> Documentation/filesystems/proc.txt | 3 ++- >> fs/proc/task_mmu.c | 20 ++++++++++++++++++++ >> 2 files changed, 22 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt >> index d4f56ec..8b30543 100644 >> --- a/Documentation/filesystems/proc.txt >> +++ b/Documentation/filesystems/proc.txt >> @@ -437,7 +437,8 @@ indicates the amount of memory currently marked as referenced or accessed. >> a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE >> and a page is modified, the file page is replaced by a private anonymous copy. >> "Swap" shows how much would-be-anonymous memory is also used, but out on >> -swap. >> +swap. For shmem mappings, "Swap" shows how much of the mapped portion of the >> +underlying shmem object is on swap. >> >> "VmFlags" field deserves a separate description. This member represents the kernel >> flags associated with the particular virtual memory area in two letter encoded >> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c >> index 956b75d..0410309 100644 >> --- a/fs/proc/task_mmu.c >> +++ b/fs/proc/task_mmu.c >> @@ -13,6 +13,7 @@ >> #include >> #include >> #include >> +#include >> >> #include >> #include >> @@ -496,6 +497,25 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, >> mss->swap += PAGE_SIZE; >> else if (is_migration_entry(swpent)) >> page = migration_entry_to_page(swpent); >> + } else if (IS_ENABLED(CONFIG_SHMEM) && IS_ENABLED(CONFIG_SWAP) && >> + pte_none(*pte) && vma->vm_file) { >> + struct address_space *mapping = >> + file_inode(vma->vm_file)->i_mapping; >> + >> + /* >> + * shmem does not use swap pte's so we have to consult >> + * the radix tree to account for swap >> + */ >> + if (shmem_mapping(mapping)) { >> + page = find_get_entry(mapping, pgoff); >> + if (page) { >> + if (radix_tree_exceptional_entry(page)) >> + mss->swap += PAGE_SIZE; >> + else >> + page_cache_release(page); >> + } >> + page = NULL; >> + } >> } >> >> if (!page) >> -- >> 2.1.4 >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org > -- > To unsubscribe from this list: send the line "unsubscribe linux-doc" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > --------------080407040304000000060205 Content-Type: text/plain; charset=UTF-8; name="shmem-show-swap-usage-in-smaps" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="shmem-show-swap-usage-in-smaps" c2htZW06IHNob3cgc3dhcCB1c2FnZSBpbiBzbWFwcwoKRnJvbTogS29uc3RhbnRpbiBLaGxl Ym5pa292IDxraGxlYm5pa292QHlhbmRleC10ZWFtLnJ1PgoKU2lnbmVkLW9mZi1ieTogS29u c3RhbnRpbiBLaGxlYm5pa292IDxraGxlYm5pa292QHlhbmRleC10ZWFtLnJ1PgotLS0KIGZz L3Byb2MvdGFza19tbXUuYyB8ICAgIDMgKysrCiBpbmNsdWRlL2xpbnV4L21tLmggfCAgICAy ICsrCiBtbS9zaG1lbS5jICAgICAgICAgfCAgICA4ICsrKysrKysrCiAzIGZpbGVzIGNoYW5n ZWQsIDEzIGluc2VydGlvbnMoKykKCmRpZmYgLS1naXQgYS9mcy9wcm9jL3Rhc2tfbW11LmMg Yi9mcy9wcm9jL3Rhc2tfbW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ribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org