From patchwork Sun Aug 30 20:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745329 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E171113B1 for ; Sun, 30 Aug 2020 20:59:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A20A3206FA for ; Sun, 30 Aug 2020 20:59:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oRJZiql1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A20A3206FA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DD24D6B0002; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D84AE6B0003; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C724B6B0005; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id AFAAC6B0002 for ; Sun, 30 Aug 2020 16:59:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 77905180AD811 for ; Sun, 30 Aug 2020 20:59:39 +0000 (UTC) X-FDA: 77208451278.15.skate61_0e000ed2708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 4BE491814B0C1 for ; Sun, 30 Aug 2020 20:59:39 +0000 (UTC) X-Spam-Summary: 1,0,0,5c9482af6f33dc2a,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:968:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6119:6261:6653:7875:7903:8957:10004:10400:11026:11473:11658:11914:12043:12297:12438:12517:12519:12555:12679:12740:12895:12986:13069:13311:13357:13439:14096:14097:14181:14394:14659:14721:21060:21080:21324:21433:21444:21451:21627:21740:21990:30003:30012:30041:30054:30070,0,RBL:209.85.167.194:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y851cknzdki1e9s4tm1izapbxcfocar3xr38jjs6jces8kf46js6can44c64j.3s7zhydxcxxdm79mc7deepqm7w5t9pa9xdi49x3yhxsjsewssnze97zin7g77w5.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: skate61_0e000ed2708a X-Filterd-Recvd-Size: 4997 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 20:59:38 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id z195so5470651oia.6 for ; Sun, 30 Aug 2020 13:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=QBRmCzycKmVnu23sFsGovUalfChtQnjWcQWYwI41Axs=; b=oRJZiql1EBss2KvDcVmuLG7L3aCyu2+FBgk3j1giZZqACibEjKQb6SkstVBGYZU4QK bRrTWKp2d3YEVyAooD3KGlCqvmb6iSkk4Me6fnFWAAquDC1qrySjhUCG2z/DiQ3qN7qh mWKoNV40sLxpuJbCb8yMKMfwcLwJtPPdadVpvHiX/sUfeVrFocScInFqHGt2zKRCHjLD hXWib8afQ6yXkkv7yDORDIYjd42qidf6OqaPSyyRGcQIAXEIQPbSC17BKRwiURY+uoLm TiKpyPEFCFrS7VE1GQ1LnEdUuPjBlcxhYR5ZNIaPhWTWW8O252C6J+xMDzYWhX7KV7el PU9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=QBRmCzycKmVnu23sFsGovUalfChtQnjWcQWYwI41Axs=; b=l2PjJyke6x6XV0PVs+B4VNThmOvLGoTjklv5ioSa+5DMVjerdAGhkW+2J+gSO/jzwD D0R7+8plmY7xSRzpRg+qNpk/5EpNSVpT452gTsZaxHH12EeugwbhxcrhrDb2ruA2Baom X9K42jJmmwG5Sn37JZ91HVapO2I6vQDCV7hogGQBvU/CceFLGp0guFrkfhxw/fAR0FB2 eY6OssmEHtFfneJGoV/xzkvg/SnU84Tc8UhtiDOvfGYpY/kTYETDUPv56XKuKDjRtTv+ EcQyY43cw7JUdW11B4JRRAx8T30qo0rKHVVZI3zRFYbZfugTppuWL0T5IvRaCjOWJY7x WmfQ== X-Gm-Message-State: AOAM530F3qQ5OGNNCFm/ZLu6rWJm3yAvirYbp49sfuwfC95BwefsjrTf QTTHvGbzmL2SAAxGhw2uF7F4iw== X-Google-Smtp-Source: ABdhPJxxjozAFzN+mLHtGpaXsRTl7d/7QcyQjmZRGz/hgM/tIVGeTiFgtm4/XScrqZiVh2LIn3H+bg== X-Received: by 2002:aca:1904:: with SMTP id l4mr1911081oii.67.1598821178001; Sun, 30 Aug 2020 13:59:38 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w136sm1256385oif.14.2020.08.30.13.59.36 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 13:59:36 -0700 (PDT) Date: Sun, 30 Aug 2020 13:59:35 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/5] ksm: reinstate memcg charge on copied pages In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 4BE491814B0C1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In 5.8 some instances of memcg charging in do_swap_page() and unuse_pte() were removed, on the understanding that swap cache is now already charged at those points; but a case was missed, when ksm_might_need_to_copy() has decided it must allocate a substitute page: such pages were never charged. Fix it inside ksm_might_need_to_copy(). This was discovered by Alex Shi's prospective commit "mm/memcg: warning on !memcg after readahead page charged". But there is a another surprise: this also fixes some rarer uncharged PageAnon cases, when KSM is configured in, but has never been activated. ksm_might_need_to_copy()'s anon_vma->root and linear_page_index() check sometimes catches a case which would need to have been copied if KSM were turned on. Or that's my optimistic interpretation (of my own old code), but it leaves some doubt as to whether everything is working as intended there - might it hint at rare anon ptes which rmap cannot find? A question not easily answered: put in the fix for missed memcg charges. Fixes: 4c6355b25e8b ("mm: memcontrol: charge swapin pages on instantiation") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org # v5.8 Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner --- mm/ksm.c | 4 ++++ 1 file changed, 4 insertions(+) --- 5.9-rc2/mm/ksm.c 2020-08-16 17:32:50.645506940 -0700 +++ linux/mm/ksm.c 2020-08-28 17:42:07.967278385 -0700 @@ -2582,6 +2582,10 @@ struct page *ksm_might_need_to_copy(stru return page; /* let do_swap_page report the error */ new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); + if (new_page && mem_cgroup_charge(new_page, vma->vm_mm, GFP_KERNEL)) { + put_page(new_page); + new_page = NULL; + } if (new_page) { copy_user_highpage(new_page, page, address, vma); From patchwork Sun Aug 30 21:01:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B18F14E5 for ; Sun, 30 Aug 2020 21:01:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D15B82083E for ; Sun, 30 Aug 2020 21:01:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oFyFWS/k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D15B82083E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 08CDA6B0002; Sun, 30 Aug 2020 17:01:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 040076B0003; Sun, 30 Aug 2020 17:01:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94636B0005; Sun, 30 Aug 2020 17:01:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id D01776B0002 for ; Sun, 30 Aug 2020 17:01:34 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8FD18363C for ; Sun, 30 Aug 2020 21:01:34 +0000 (UTC) X-FDA: 77208456108.13.vase16_6214e4a2708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 66E5C18140B67 for ; Sun, 30 Aug 2020 21:01:34 +0000 (UTC) X-Spam-Summary: 1,0,0,435fdf92cb353c54,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3866:3870:3871:3872:3874:4321:5007:6261:6653:7875:8660:8957:10004:10400:11026:11232:11658:11914:12043:12297:12517:12519:12555:12740:12895:12986:13069:13148:13149:13230:13311:13357:13439:14096:14097:14181:14394:14659:14721:21060:21080:21324:21444:21451:21627:21939:30054,0,RBL:209.85.210.65:@google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrwk8bh9tt6cw3zxgcia85bbposycd7ojnkisg3hygda3tz98m4u5s7t1rw79.km94j4yyoza99eus3ikrag7beu1d53gfjzgamsiytaoqd7f1hpmazqm9wisj3ge.1-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:22,LUA_SUMMARY:none X-HE-Tag: vase16_6214e4a2708a X-Filterd-Recvd-Size: 4132 Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 21:01:33 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id j3so3728466otk.13 for ; Sun, 30 Aug 2020 14:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=0A0MgBvdZsn83Ew2Ktjq3B8TXEsbXPWHsWkGfR3n5Sk=; b=oFyFWS/knp2ok2Qu0qsMN8fKLiiU0kOo/mIL5IkekajG5x9dgm1oAvakoa5SgfZHsu 1qzYznn+LwXijJPZS5UvQ28q4NzUqmQb5JYoYoaQQusdmgpdVzkKh2AOHSU9euxcpNYl omLFmPd1dP35wP+etXy3lmrM1uUlWvqnZPAKCuZ/k8Dno8MbpcvA8qEhhlhnzQXBYM+B ux5CuQ7sti0552QPWjIrs+ZMNYXdqpMx98JzBmfA6sPypX7LUj7UIwUjrVLfIvb3FIfd T5tlwA6YskZ2woohS40ycZRntDy8zFveF5niV8KmeDlng4hl5LLHWoI5KQ7NQ/26N/xN dVTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=0A0MgBvdZsn83Ew2Ktjq3B8TXEsbXPWHsWkGfR3n5Sk=; b=JzNraY8pzSD12oAYQ/iswgkJ+Sqt5IAByuvm9YuT/HwYslwNx/ypwOoO33xGIxYnP6 hpzs1ZyGgfF6KEfY4uwlBPendIdoHs0NRxIuOWieRBFpo63+UFETIv0zJmUwOzGRX4Ko jiyW/rJzTdW5e/hFjWQl+h1Kfj7ESbFOE9xFgnd87uFkj8tOAX7iTHYDbtHQ+WaFGAJH 2bKVWPiiFgQkimdrSWcibYL0PVfvCd/agbxdALdWIdNY1mFNQ/MuUziinstDOEtotI/L sQvQnMhhUuNlxDYEXzylDr43G8qE40Tnl+iqFGO7EcN9eVonFus2cnX+3091BmNBj6mJ SyYg== X-Gm-Message-State: AOAM531MxDWEHhGVyRY7x/+njrzakO2GMWTg7553Eb2H0V5bURuT8VaG v1GR60G7J5r/lnoB7xxL6VKGRQ== X-Google-Smtp-Source: ABdhPJyM3ZCANKZOyGmfG66cOB7Sxsfltxqe3tzoqaKIbYnuzUsBOB5hyE7Vr76l2sr1FdMpsJQYTw== X-Received: by 2002:a9d:24c6:: with SMTP id z64mr2594644ota.97.1598821293211; Sun, 30 Aug 2020 14:01:33 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id m11sm281916ooe.43.2020.08.30.14.01.31 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 14:01:32 -0700 (PDT) Date: Sun, 30 Aug 2020 14:01:30 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/5] mm: migration of hugetlbfs page skip memcg In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 66E5C18140B67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: hugetlbfs pages do not participate in memcg: so although they do find most of migrate_page_states() useful, it would be better if they did not call into mem_cgroup_migrate() - where Qian Cai reported that LTP's move_pages12 triggers the warning in Alex Shi's prospective commit "mm/memcg: warning on !memcg after readahead page charged". Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner --- This fixes a likely future warning, but is just a cleanup right now. mm/migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- 5.9-rc2/mm/migrate.c 2020-08-16 17:32:50.665507048 -0700 +++ linux/mm/migrate.c 2020-08-28 17:42:07.967278385 -0700 @@ -668,7 +668,8 @@ void migrate_page_states(struct page *ne copy_page_owner(page, newpage); - mem_cgroup_migrate(page, newpage); + if (!PageHuge(page)) + mem_cgroup_migrate(page, newpage); } EXPORT_SYMBOL(migrate_page_states); From patchwork Sun Aug 30 21:04:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C1CD739 for ; Sun, 30 Aug 2020 21:04:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C2C6F20936 for ; Sun, 30 Aug 2020 21:04:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mLgm8Hki" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2C6F20936 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0B0A6B0002; Sun, 30 Aug 2020 17:04:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EBB266B0003; Sun, 30 Aug 2020 17:04:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD18B6B0005; Sun, 30 Aug 2020 17:04:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id C91376B0002 for ; Sun, 30 Aug 2020 17:04:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 82E82180AD804 for ; Sun, 30 Aug 2020 21:04:57 +0000 (UTC) X-FDA: 77208464634.29.trees47_300eb252708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 4888D18086CCB for ; Sun, 30 Aug 2020 21:04:57 +0000 (UTC) X-Spam-Summary: 1,0,0,214941bf49635d61,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:966:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3868:3870:3871:3874:4321:4385:5007:6261:6653:6742:8957:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12297:12438:12517:12519:12555:12679:12740:12895:12986:13069:13311:13357:13439:14093:14096:14097:14181:14394:14659:14721:19904:19999:21080:21324:21444:21451:21627:21740:30034:30054:30056:30070:30075,0,RBL:209.85.167.195:@google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygkyxurb1zjq8dfm6uazcypq693opdn9ftmjunxyjoess3xkd65tgebf5hqnc.ojeb4awrzfjxh3qq437n67irt9wrxezipzaes78jtnds1wsbhi7fq81p74mh4cm.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: trees47_300eb252708a X-Filterd-Recvd-Size: 4824 Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 21:04:56 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id u24so5487476oic.7 for ; Sun, 30 Aug 2020 14:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=coS1VgOeVvuW3zilDte6RopNvB+JCPXBV06ZRlXDP00=; b=mLgm8HkihKv7FyGuefBErbKi1q1X3jgYF1hFyRbkUtb+OlouRU6smur6+yj1xhcX5o mudVlzmxyk3BIsBQ+jxr0UGffsZM9yHUxOWGMJy6iP4fPeUNHnCpypxiDiDSe26OP8CP WaD1ejKPn5MwG679WL8r5CkBr4ucRNV4Fki7DfaAZdyGCroDviXtVHCUmZWgTa0ggtUP ifGpay17H5XsEl31i4ALDPfoMpW26ISN3x0V7bMmMeOak1enznroTYmgomSaLQ/7zVcH voFY5z0lGiViIVUs/JP2LEhQwAzltEAb9mLieOjaBjUcg+uiL5oPQeDt9Li8eYlhKfYv 2cdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=coS1VgOeVvuW3zilDte6RopNvB+JCPXBV06ZRlXDP00=; b=V38iiPezJobNPdOEHWWSz3EDsOKntnZH8tmD0hd2uK+apmDxYH9tSYWwHkbtzHNnaY a+XFHsgv+6EooBwXq6bLssRD8BKSbOAIkjonKc7x6Dlv0wR07kkfhVSNLuMxPIoxeAgv ittMc+QfLXODw9xo32PP88JLM8+lFF7DCOIwxEEn4DugKOtqMhVp4JiJK4tW5HRcAT5x dUX2V5Cnyd2/WVSCgtSLsQvZDVXFw/cmHt04Es6TsbZAL7X4boGiYMpB55Jfw18nPT+A affVAidGfjnEYoBLFrlENIIY6aKyz2sJoo51bMO9S8U9Nx7QvehtHfD6aHuIS5fPBqwf k8NQ== X-Gm-Message-State: AOAM532NZZG5iWuRvm6NTVjxauUyihZfF3/NjuZBP6+52wIHRC6FounW I10eHCUocMtRcf1hZTvH6DCVVA== X-Google-Smtp-Source: ABdhPJyBDjSpD7vn8efGsx/WG5uLd+GklOI9Mc88ks1Nx40bsNuBq8J3UE90x7tcCu+8R+f7RbVQiQ== X-Received: by 2002:a05:6808:b36:: with SMTP id t22mr1874161oij.159.1598821496074; Sun, 30 Aug 2020 14:04:56 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id z10sm1362907otk.6.2020.08.30.14.04.54 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 14:04:55 -0700 (PDT) Date: Sun, 30 Aug 2020 14:04:53 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , Chris Wilson , Kuo-Hsin Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/5] shmem: shmem_writepage() split unlikely i915 THP Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 4888D18086CCB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: drivers/gpu/drm/i915/gem/i915_gem_shmem.c contains a shmem_writeback() which calls shmem_writepage() from a shrinker: that usually works well enough; but if /sys/kernel/mm/transparent_hugepage/shmem_enabled has been set to "force" (documented as "Force the huge option on for all - very useful for testing"), shmem_writepage() is surprised to be called with a huge page, and crashes on the VM_BUG_ON_PAGE(PageCompound) (I did not find out where the crash happens when CONFIG_DEBUG_VM is off). LRU page reclaim always splits the shmem huge page first: I'd prefer not to demand that of i915, so check and split compound in shmem_writepage(). Fixes: 2d6692e642e7 ("drm/i915: Start writeback from the shrinker") Signed-off-by: Hugh Dickins Cc: stable@vger.kernel.org # v5.3+ Reviewed-by: Shakeel Butt --- I've marked this for stable just for the info, but the number of users affected is very probably 1, so please feel free to delete that marking. mm/shmem.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- 5.9-rc2/mm/shmem.c 2020-08-16 17:32:50.693507198 -0700 +++ linux/mm/shmem.c 2020-08-28 17:35:08.326024349 -0700 @@ -1362,7 +1362,15 @@ static int shmem_writepage(struct page * swp_entry_t swap; pgoff_t index; - VM_BUG_ON_PAGE(PageCompound(page), page); + /* + * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "force", + * then drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, + * and its shmem_writeback() needs them to be split when swapping. + */ + if (PageTransCompound(page)) + if (split_huge_page(page) < 0) + goto redirty; + BUG_ON(!PageLocked(page)); mapping = page->mapping; index = page->index; From patchwork Sun Aug 30 21:08:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAC4614E5 for ; Sun, 30 Aug 2020 21:08:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 745B02083E for ; Sun, 30 Aug 2020 21:08:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c4OqQCxX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 745B02083E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AEA396B0002; Sun, 30 Aug 2020 17:08:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A9A396B0003; Sun, 30 Aug 2020 17:08:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98A336B0005; Sun, 30 Aug 2020 17:08:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 810986B0002 for ; Sun, 30 Aug 2020 17:08:21 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 442A4180AD815 for ; Sun, 30 Aug 2020 21:08:21 +0000 (UTC) X-FDA: 77208473202.17.war31_600def32708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 16172180D0180 for ; Sun, 30 Aug 2020 21:08:21 +0000 (UTC) X-Spam-Summary: 1,0,0,0ff3d1fdf091adef,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2895:2898:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6261:6653:6742:7903:8957:10004:10400:11026:11232:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13161:13229:13439:14093:14097:14181:14394:14659:14721:21060:21063:21080:21444:21450:21451:21627:21796:21939:21987:30034:30036:30054:30056:30070:30090,0,RBL:209.85.167.193:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr8e865wz8ymowep73c898u11edoc14rhxdf65a1b1t9ykfm98xg11uj3kix3.166ttzmkxeozbzn4t8iutdxd7kr4g7t5qjes7yee9f7xsea7baafkqcdogq1etx.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_S UMMARY:n X-HE-Tag: war31_600def32708a X-Filterd-Recvd-Size: 5672 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 21:08:20 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id k4so5503438oik.2 for ; Sun, 30 Aug 2020 14:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=SQ10D8PXryeEKHHcl5IvJgd6P48aMcyJPD1+SoD+oOw=; b=c4OqQCxXIwZCv3JjpmkYk1C/CeDsSc970MD8kj38easVa+rgeXjtnreeKAvbX5dnN9 d2uuNuM4vPcJmTcVou5fUb4QsSDGIo0I3jzh7ZNG+qN6GK/hSQ+UkqXT4pYaGthcv1VY 89WTQRrQljR99h7ywkXXy3vo2t9LlTpEqqRthmrCKuytS4dvmws+u25TJBxt6AwCfwvX bT4yk0N1mRAjDTukMmYU2jHo7PXwaeoqAUCooMsaalgiXLhzYKEMF9PsTlbNZOGJBrAa PFUs3sGOo/dZLqlr4+danZhsgj+kTFIxVg381SJZ22wuz518PSM0dkFR3E6QF7kOlmHp TUfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=SQ10D8PXryeEKHHcl5IvJgd6P48aMcyJPD1+SoD+oOw=; b=UtdV8WTKR0hmXKHBetKzwH5rWvmJZnaq20FgXY5oNaDRJ1eebWphcHnPAifKIw6GIe EotBCq9fsHWk6u5dpCkLu95Xmn723vp6Gu72XVrSvn/g24WVjmpgGUcwp85eqw4H7WZY qGOWwBYyjWfPu74rlxfL1PLUZQQdFT9HiyeGlpdOQtTAjXXnpltMXG1AcsNjmGF9qZ0B S1Ik/Zjf6ZE9x3HdUqVuGbZ8N0IP4sKQwpQhZkRUAu6dEA4iixDf3cOiJk2L+g/Gvm+X 8kR4HutLx6rTLeriUEUcRT4liN0q7yj8v1dN+o2hRXY67d1Va77aC7t9VLW/Z4U4eCNV AmyA== X-Gm-Message-State: AOAM531r9G5x/xTJvwy4ttS+uRqjLgKU9DmRTu3jvtWav2dEoQ7PDYyu 3agDje7uk6A3Tj1Co05gTlMDhw== X-Google-Smtp-Source: ABdhPJxF1SCIvzAbelWpBIoB9i54xpvq6aZj7/FIsSEv2EFOm/IpDLQv50VMevxq6JU/ORrsgv5lJQ== X-Received: by 2002:aca:fc85:: with SMTP id a127mr1801672oii.148.1598821699723; Sun, 30 Aug 2020 14:08:19 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 63sm1408348ooj.32.2020.08.30.14.08.17 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 14:08:18 -0700 (PDT) Date: Sun, 30 Aug 2020 14:08:16 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , Chris Wilson , Kuo-Hsin Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/5] mm: fix check_move_unevictable_pages() on THP In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: 16172180D0180 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: check_move_unevictable_pages() is used in making unevictable shmem pages evictable: by shmem_unlock_mapping(), drm_gem_check_release_pagevec() and i915/gem check_release_pagevec(). Those may pass down subpages of a huge page, when /sys/kernel/mm/transparent_hugepage/shmem_enabled is "force". That does not crash or warn at present, but the accounting of vmstats unevictable_pgs_scanned and unevictable_pgs_rescued is inconsistent: scanned being incremented on each subpage, rescued only on the head (since tails already appear evictable once the head has been updated). 5.8 commit 5d91f31faf8e ("mm: swap: fix vmstats for huge page") has established that vm_events in general (and unevictable_pgs_rescued in particular) should count every subpage: so follow that precedent here. Do this in such a way that if mem_cgroup_page_lruvec() is made stricter (to check page->mem_cgroup is always set), no problem: skip the tails before calling it, and add thp_nr_pages() to vmstats on the head. Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Acked-by: Yang Shi --- Nothing here worth going to stable, since it's just a testing config that is fixed, whose event numbers are not very important; but this will be needed before Alex Shi's warning, and might as well go in now. The callers of check_move_unevictable_pages() could be optimized, to skip over tails: but Matthew Wilcox has other changes in flight there, so let's skip the optimization for now. mm/vmscan.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- 5.9-rc2/mm/vmscan.c 2020-08-16 17:32:50.721507348 -0700 +++ linux/mm/vmscan.c 2020-08-28 17:47:10.595580876 -0700 @@ -4260,8 +4260,14 @@ void check_move_unevictable_pages(struct for (i = 0; i < pvec->nr; i++) { struct page *page = pvec->pages[i]; struct pglist_data *pagepgdat = page_pgdat(page); + int nr_pages; + + if (PageTransTail(page)) + continue; + + nr_pages = thp_nr_pages(page); + pgscanned += nr_pages; - pgscanned++; if (pagepgdat != pgdat) { if (pgdat) spin_unlock_irq(&pgdat->lru_lock); @@ -4280,7 +4286,7 @@ void check_move_unevictable_pages(struct ClearPageUnevictable(page); del_page_from_lru_list(page, lruvec, LRU_UNEVICTABLE); add_page_to_lru_list(page, lruvec, lru); - pgrescued++; + pgrescued += nr_pages; } } From patchwork Sun Aug 30 21:09:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 11745337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3C16109B for ; Sun, 30 Aug 2020 21:09:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7660F2083E for ; Sun, 30 Aug 2020 21:09:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i4m50/xw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7660F2083E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE9FF6B0002; Sun, 30 Aug 2020 17:09:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A99C86B0003; Sun, 30 Aug 2020 17:09:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98B4F6B0005; Sun, 30 Aug 2020 17:09:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 830F06B0002 for ; Sun, 30 Aug 2020 17:09:57 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DA0303643 for ; Sun, 30 Aug 2020 21:09:56 +0000 (UTC) X-FDA: 77208477192.04.deer65_4a064cc2708a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id B392B8008B0C for ; Sun, 30 Aug 2020 21:09:56 +0000 (UTC) X-Spam-Summary: 1,0,0,7a9140488d97ffaf,d41d8cd98f00b204,hughd@google.com,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1544:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2904:3138:3139:3140:3141:3142:3152:3354:3503:3504:3865:3866:3867:3868:3870:3871:3872:3874:4118:4321:5007:6117:6261:6653:8957:9010:10004:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12740:12895:12986:13161:13229:13439:14096:14097:14181:14394:14659:14721:21080:21433:21444:21451:21627:21740:21809:21966:21990:30054:30056:30090,0,RBL:209.85.161.66:@google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y89sxex545iu697wjkht16qyij1ockw4tfyjkmmzpgn51zcqi38gsq6cptubh.m18pmwn9z36wsgh7sxspjbxr1cn1kek4m8p78ajdko7ymdwuq53q7h5kipe5smy.e-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: deer65_4a064cc2708a X-Filterd-Recvd-Size: 7289 Received: from mail-oo1-f66.google.com (mail-oo1-f66.google.com [209.85.161.66]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Sun, 30 Aug 2020 21:09:56 +0000 (UTC) Received: by mail-oo1-f66.google.com with SMTP id x6so972456ooe.8 for ; Sun, 30 Aug 2020 14:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=oObpY48XdTvUxTDfJa2g2q0M3QkpTwHKIJDdTDdY8Dc=; b=i4m50/xw542tFUgH/mrLiPw3QaF7oJPHvcvyrQNdsD5PuIsn7W3hy9gvCOKFahZdG4 x5wlT7nWsbtH0ybkl7rrV0P/j7CTpOv6XGZxnfKp7bIPvrdVPi5Kz6DUkWYiIyx6dm/9 d6Bh1gdyGS+EtQl9F8IQcVaysU0gPaoNSzvW86KV3kxakcIB7/9zL38vCYITyJUr1nZt GzugCy2VRn7kA9ZpU/B/0BJ34vqlU8TURYZUieladRuszVW7ekPnkeSBcQO9DyHnNF0y K3Cqt7A7xgxdhqMkLo+CkA7qs8Nti70TWjutypOfPxq2Xfeq6UE/upeJjfXLJdwLgXAM NQpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=oObpY48XdTvUxTDfJa2g2q0M3QkpTwHKIJDdTDdY8Dc=; b=m0Vl5yaXjfyowkUBCehCeHXjqQ+45h3NyyULtfyTTq9DgXX7AQByTvOwpQhRw9U6N7 WScf2tNIbrPnS9nu1H/Nf4Nh9gwzPpaiSuFC/wSH0LzvLBVZqtsYVBpLz1Mn2hPmYi4A Mqhy2Pif3bdJucw2uyKkXXlzhLZNtedCgORvZUg3vTKh353/LjZ45onJ6K5jtgDr10PY wvKF5lR4z0mxF3cBqV/aqxFaU+OPUFJsefmb4ANpdIwtFtpEbQIPy0nRUC/QJbRo3sVA 7mrX6DcA6wWwYRrvGUQeV1lusl5RJt6Cop3kQ3yOqK0ISvqiaV1pVrv/47eq26LIMZ6w CKCg== X-Gm-Message-State: AOAM5314uSOllTL887SVWkupDFTWyjhn58xXFjK+3Uu42be4fCT3C+z+ NhUk+GlH4HkWW1ZIcByHiQ4+mQ== X-Google-Smtp-Source: ABdhPJwMB1Gz3yryOwBzNp2wDtYJ5LUzxLS3b/PHz2HcPX4AOSw58hhGqnGTSjHBrof7blTxs0ABYg== X-Received: by 2002:a4a:bb05:: with SMTP id f5mr3475000oop.5.1598821795429; Sun, 30 Aug 2020 14:09:55 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id g4sm1363777otq.33.2020.08.30.14.09.53 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Sun, 30 Aug 2020 14:09:54 -0700 (PDT) Date: Sun, 30 Aug 2020 14:09:52 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/5] mlock: fix unevictable_pgs event counts on THP In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 X-Rspamd-Queue-Id: B392B8008B0C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 5.8 commit 5d91f31faf8e ("mm: swap: fix vmstats for huge page") has established that vm_events should count every subpage of a THP, including unevictable_pgs_culled and unevictable_pgs_rescued; but lru_cache_add_inactive_or_unevictable() was not doing so for unevictable_pgs_mlocked, and mm/mlock.c was not doing so for unevictable_pgs mlocked, munlocked, cleared and stranded. Fix them; but THPs don't go the pagevec way in mlock.c, so no fixes needed on that path. Fixes: 5d91f31faf8e ("mm: swap: fix vmstats for huge page") Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Acked-by: Yang Shi --- I've only checked UNEVICTABLEs: there may be more inconsistencies left. The check_move_unevictable_pages() patch brought me to this one, but this is more important because mlock works on all THPs, without needing special testing "force". But, it's still just monotonically increasing event counts, so not all that important. mm/mlock.c | 24 +++++++++++++++--------- mm/swap.c | 6 +++--- 2 files changed, 18 insertions(+), 12 deletions(-) --- 5.9-rc2/mm/mlock.c 2020-08-16 17:32:50.665507048 -0700 +++ linux/mm/mlock.c 2020-08-28 17:42:07.975278411 -0700 @@ -58,11 +58,14 @@ EXPORT_SYMBOL(can_do_mlock); */ void clear_page_mlock(struct page *page) { + int nr_pages; + if (!TestClearPageMlocked(page)) return; - mod_zone_page_state(page_zone(page), NR_MLOCK, -thp_nr_pages(page)); - count_vm_event(UNEVICTABLE_PGCLEARED); + nr_pages = thp_nr_pages(page); + mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages); + count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages); /* * The previous TestClearPageMlocked() corresponds to the smp_mb() * in __pagevec_lru_add_fn(). @@ -76,7 +79,7 @@ void clear_page_mlock(struct page *page) * We lost the race. the page already moved to evictable list. */ if (PageUnevictable(page)) - count_vm_event(UNEVICTABLE_PGSTRANDED); + count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages); } } @@ -93,9 +96,10 @@ void mlock_vma_page(struct page *page) VM_BUG_ON_PAGE(PageCompound(page) && PageDoubleMap(page), page); if (!TestSetPageMlocked(page)) { - mod_zone_page_state(page_zone(page), NR_MLOCK, - thp_nr_pages(page)); - count_vm_event(UNEVICTABLE_PGMLOCKED); + int nr_pages = thp_nr_pages(page); + + mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages); + count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages); if (!isolate_lru_page(page)) putback_lru_page(page); } @@ -138,7 +142,7 @@ static void __munlock_isolated_page(stru /* Did try_to_unlock() succeed or punt? */ if (!PageMlocked(page)) - count_vm_event(UNEVICTABLE_PGMUNLOCKED); + count_vm_events(UNEVICTABLE_PGMUNLOCKED, thp_nr_pages(page)); putback_lru_page(page); } @@ -154,10 +158,12 @@ static void __munlock_isolated_page(stru */ static void __munlock_isolation_failed(struct page *page) { + int nr_pages = thp_nr_pages(page); + if (PageUnevictable(page)) - __count_vm_event(UNEVICTABLE_PGSTRANDED); + __count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages); else - __count_vm_event(UNEVICTABLE_PGMUNLOCKED); + __count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages); } /** --- 5.9-rc2/mm/swap.c 2020-08-16 17:32:50.709507284 -0700 +++ linux/mm/swap.c 2020-08-28 17:42:07.975278411 -0700 @@ -494,14 +494,14 @@ void lru_cache_add_inactive_or_unevictab unevictable = (vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) == VM_LOCKED; if (unlikely(unevictable) && !TestSetPageMlocked(page)) { + int nr_pages = thp_nr_pages(page); /* * We use the irq-unsafe __mod_zone_page_stat because this * counter is not modified from interrupt context, and the pte * lock is held(spinlock), which implies preemption disabled. */ - __mod_zone_page_state(page_zone(page), NR_MLOCK, - thp_nr_pages(page)); - count_vm_event(UNEVICTABLE_PGMLOCKED); + __mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages); + count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages); } lru_cache_add(page); }