From patchwork Wed Apr 1 14:17:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 11469127 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 9FF7C81 for ; Wed, 1 Apr 2020 14:20:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F55620705 for ; Wed, 1 Apr 2020 14:20:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tepDJp6V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F55620705 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E2298E0006; Wed, 1 Apr 2020 10:20:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 76BCF8E0001; Wed, 1 Apr 2020 10:20:17 -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 6647B8E0006; Wed, 1 Apr 2020 10:20:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 4BC5F8E0001 for ; Wed, 1 Apr 2020 10:20:17 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0F80B40DD for ; Wed, 1 Apr 2020 14:20:17 +0000 (UTC) X-FDA: 76659496074.29.hook34_76d3a03fd0531 X-Spam-Summary: 2,0,0,f666479cb7348c19,d41d8cd98f00b204,kernelfans@gmail.com,,RULES_HIT:41:152:355:379:541:800:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3354:3865:3867:3868:3870:3871:3872:4117:4605:5007:6119:6261:6653:7514:7903:9121:9413:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13161:13229:13846:13894:14096:14097:14181:14394:14659:14687:14721:21080:21444:21451:21627:21666:21740:21990:30003:30012:30054:30064:30090,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: hook34_76d3a03fd0531 X-Filterd-Recvd-Size: 6312 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Wed, 1 Apr 2020 14:20:16 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id w3so9686379plz.5 for ; Wed, 01 Apr 2020 07:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3w8U8eUpbxjczXIbE84xn0ieCjptlY7uxoIMsFwJA9s=; b=tepDJp6VfcT2Ri2fMsD41rRtuJQc4MLb6lzVXh2svkfQGQGSBK8jOCfdvPfa5VUWcB 1b815szyMrZ6mEl00BNFsBjhY/vFwAzyd+IHHUZLWtC+7/PN3XhSkZVlgMnqH1IGtvzb 2cEfDs2kvDHN47nFRtsWIU65OaOvo8mIHB3s3hbmUgYje5i5oD8e1w3IlD7/okZtxYui J8AY7pxt3N7JRdhgjVj2FAamTTYUH58YAoPKXEarLX5+a9U9nermI4VEDO9LYUXFmXQj psDU0JYlhALlv4fm9kZR9UKhNkbnB1XKJrvAWWcMQgJMw+3uyK2FdAFNT4cujXxiqrwi Y+bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3w8U8eUpbxjczXIbE84xn0ieCjptlY7uxoIMsFwJA9s=; b=pmg844+mfFUqVVSz0GnBTiXYiU8DyTXRQoF7iN/owcVbCqlSVzKQzetdivJ3yuG4BZ eG/pBFeQ1mUOVFnD6dkoX/GzYkGOMqXrDLSt2mvlUDZu1sQj5qeSrF6k6pyaJpvQCnD1 J8tV5rQaVBUs+1hfIkLlyLGBBOtTXcNAXgk4P0JdxUvOBVXmwHAOwscnFrFF8crdtLum UIc1+EOnFsA4jXZa9S51zaoIvUoSoOHBytSUH70qCRoRIcgQI8JeEiidOnTTMswmGWau mcjjY2d9wblzjWV3aS0VCVitDWB+bhYt7nxXePrtglyqpvvjpxOEVmufDiHx+4PPSVvd e6iw== X-Gm-Message-State: AGi0PuYZnX+tvoz2ZIYu1gUQKms6BKq3c5KPL5pK00DHBix6SgcRTniT L1ldLazFIRTn+kDKqNPErl+80QevwA== X-Google-Smtp-Source: APiQypI8QrXIIoTnew11fX4ZRvQKSDBZOTI5kkK+r3gh/CvBQnZMVjEiQ8uiOaCUcAJvfoE0C72LkQ== X-Received: by 2002:a17:90b:46c9:: with SMTP id jx9mr5339028pjb.2.1585750815146; Wed, 01 Apr 2020 07:20:15 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e7sm1723449pfm.3.2020.04.01.07.20.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2020 07:20:14 -0700 (PDT) From: Pingfan Liu To: linux-mm@kvack.org Cc: Pingfan Liu , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Michal Hocko , Ralph Campbell , Balbir Singh , Dan Williams , John Hubbard , "Kirill A . Shutemov" , Aneesh Kumar , Andrew Morton Subject: [PATCH] mm/rmap: fix the handling of !private device page in try_to_unmap_one() Date: Wed, 1 Apr 2020 22:17:58 +0800 Message-Id: <1585750678-5840-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584885427-4952-1-git-send-email-kernelfans@gmail.com> References: <1584885427-4952-1-git-send-email-kernelfans@gmail.com> MIME-Version: 1.0 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: This patch is a pure code refinement without any functional changes. try_to_unmap_one() is shared by try_to_unmap() and try_to_munlock(). As for unmap, if try_to_unmap_one() return true, it means the pte has been teared down and mapcount dec. Apparently the current code if (IS_ENABLED(CONFIG_MIGRATION) && (flags & TTU_MIGRATION) && is_zone_device_page(page) && !is_device_private_page(page)) return true; conflicts with this logic. Further more, as for zone_device, migration can only happen on is_device_private_page(page). For other zone_device, memmap_init_zone_device() raises an extra _refcount on all zone pages. This extra _refcount will block migration. So in try_to_unmap_one(), it can just return false for other zone device. The reason why original code happen to work one !private zone_device. -1. if page mapped, then try_to_unmap_one()->page_remove_rmap() is skipped, and finally try_to_unmap(){ return !page_mapcount(page) ? true : false;} will return false. -2. if page not mapped, the extra _refcount will prevent the migration. Signed-off-by: Pingfan Liu Cc: Jérôme Glisse Cc: Michal Hocko Cc: Ralph Campbell Cc: Balbir Singh Cc: Dan Williams Cc: John Hubbard Cc: Kirill A. Shutemov Cc: Aneesh Kumar Cc: Andrew Morton To: linux-mm@kvack.org --- v1 -> v2: improve commit log and note in code mm/rmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.7.5 diff --git a/mm/rmap.c b/mm/rmap.c index b838647..723af4f 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1358,6 +1358,10 @@ void page_remove_rmap(struct page *page, bool compound) /* * @arg: enum ttu_flags will be passed to this argument + * + * For munlock, return true if @page is not mlocked by @vma without killing pte + * For unmap, return true after tearing down pte. + * For both cases, return false if rmap_walk should be stopped. */ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, unsigned long address, void *arg) @@ -1380,7 +1384,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, if (IS_ENABLED(CONFIG_MIGRATION) && (flags & TTU_MIGRATION) && is_zone_device_page(page) && !is_device_private_page(page)) - return true; + return false; if (flags & TTU_SPLIT_HUGE_PMD) { split_huge_pmd_address(vma, address, @@ -1487,7 +1491,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, if (IS_ENABLED(CONFIG_MIGRATION) && (flags & TTU_MIGRATION) && - is_zone_device_page(page)) { + is_device_private_page(page)) { swp_entry_t entry; pte_t swp_pte;