From patchwork Fri Jan 31 01:33:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11358999 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 3D70B92A for ; Fri, 31 Jan 2020 01:35:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EEC38206F0 for ; Fri, 31 Jan 2020 01:35:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HJwE4NJr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEC38206F0 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 2E3436B0498; Thu, 30 Jan 2020 20:35:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 26C676B0499; Thu, 30 Jan 2020 20:35:20 -0500 (EST) 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 135136B049A; Thu, 30 Jan 2020 20:35:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id EE3396B0498 for ; Thu, 30 Jan 2020 20:35:19 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9D5898248047 for ; Fri, 31 Jan 2020 01:35:19 +0000 (UTC) X-FDA: 76436211558.09.waste92_4b887e53ab662 X-Spam-Summary: 2,0,0,d39718e335f8b477,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:mhocko@suse.com:mike.kravetz@oracle.com:n-horiguchi@ah.jp.nec.com:linux-man@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:967:968:973:988:989:1260:1345:1437:1535:1544:1605:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2693:2859:2902:2910:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4250:4321:4605:5007:6121:6261:6653:7514:7875:7903:9025:9391:9413:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:12986:13153:13156:13228:13845:14040:14096:14181:14394:14687:14721:21060:21080:21094:21323:21324:21433:21444:21451:21627:21666:21740:21749:21795:21819:21939:21990:30003:30006:30012:30051:30054:30064:30070,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSB L:0,DNSB X-HE-Tag: waste92_4b887e53ab662 X-Filterd-Recvd-Size: 6750 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jan 2020 01:35:18 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id z26so3629877lfg.13 for ; Thu, 30 Jan 2020 17:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=FnewTHL9O3dn1OwrugaG7gamQ9ZOrHSnXA1DIdYS5OQ=; b=HJwE4NJrHGRBsk1B67jtByJXvxTWODNgj628+KEkhJDH8IM7Bb+w5pxVHQHd8oWyTZ KXWx2H/f3AV1/vZNCF6ZHVSjrtoe1k5q2oOoyCwEXoFwi+jm5ESIRnoq4fNRzuQPOqTd XqxKFm8zLL7wZTb6o+FWhlWjP7lb3oOmLDbtS6TFopHcqeZiIf1JtNUaew9QIoAn5JhT oAtZ8JSdOY9UeDMdS3iq4iXAoOV4oK0sRJddUy35eNLaetZ5bNuI/u3GYwErifjppdgD HuoCMsp/zO6mrh8aG1EAuTE9NzMDrNSOSAPU01HMYmOA0kCptH3j9ELLsLSHe9q0e5Kq QJAA== 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; bh=FnewTHL9O3dn1OwrugaG7gamQ9ZOrHSnXA1DIdYS5OQ=; b=f89gLSRc4LyVf8sn9ggTHMvWv6j/+1xxyOXWRZiwjj50oKnDusECEipQUMqg/t2p1g ueqFCa2z8sB06zGP2aHRA6ba2HcRgnVo3lW5yMqkTIdCn5LXTDqueAUMtjxLVFVjuFBv 6yiyBCi+gJo7NSz9znEOtEweGL5vnhOozTOsFqkClSblK+jPeY5cF0kFmeKQVI2sBqs1 V1M7TGatwSGj2xaE41vID9pcjydrUS0qnG7wVGcyLmnNvfFCdaZHOgcQmURoE/f0jKgb 9Eyts8YsnkRkF7kThvpo/SfnOmKzOZeIeGCq+md1OUImJ6pFr5y+NehRLdemV0mSgXKF ofng== X-Gm-Message-State: APjAAAW7vcZTG6AyG10N4rRRFpewOR4G5n/mNvJeYEy65ktE0Hl7O+yq fb2tYYN9LgVK5cUiyhu42MoYinhxOX0= X-Google-Smtp-Source: APXvYqwe0n44cg33eDQNX+7OYgPaUbx7NfTqA6I5zmvXZ6NQ2HHM+vlGzfBSAM8yeFP6BCGyxHL2IQ== X-Received: by 2002:ac2:5979:: with SMTP id h25mr4170132lfp.203.1580434516557; Thu, 30 Jan 2020 17:35:16 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id n3sm3778613ljc.100.2020.01.30.17.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jan 2020 17:35:16 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Michal Hocko , Mike Kravetz , Naoya Horiguchi , linux-man Subject: [PATCH] mm/mempolicy: support MPOL_MF_STRICT for huge page mapping Date: Fri, 31 Jan 2020 01:33:15 +0000 Message-Id: <1580434395-9962-1-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 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: MPOL_MF_STRICT is used in mbind() for purposes: (1) MPOL_MF_STRICT is set alone without MPOL_MF_MOVE or MPOL_MF_MOVE_ALL, to check if there is misplaced page and return -EIO; (2) MPOL_MF_STRICT is set with MPOL_MF_MOVE or MPOL_MF_MOVE_ALL, to check if there is misplaced page which is failed to isolate, or page is success on isolate but failed to move, and return -EIO. For non hugepage mapping, (1) and (2) are implemented as expectation. For hugepage mapping, (1) is not implemented. And in (2), the part about failed to isolate and report -EIO is not implemented. This patch implements the missed parts for hugepage mapping. Benefits with it applied: - User space can apply same code logic to handle mbind() on hugepage and non hugepage mapping; - Reliably using MPOL_MF_STRICT alone to check whether there is misplaced page or not when bind policy on address range, especially for address range which contains both hugepage and non hugepage mapping. Analysis of potential impact on existing users: - For users who using MPOL_MF_STRICT alone, since mbind() don't report reliable answer about misplaced page, their existing code have to utilize other facilities, e.g. numa_maps of proc, to check misplaced page. After this patch applied, that dedicated checking will still work without been impacted; - For users who using MPOL_MF_STRICT with MPOL_MF_MOVE or MPOL_MF_MOVE_ALL, the semantic about some pages could not be moved will not be changed by this patch, because failed to isolate and failed to move have same effects to users, so their existing code will not be impacted. In mbind man page, the note about 'MPOL_MF_STRICT is ignored on huge page mappings' can be removed after this patch is applied. Signed-off-by: Li Xinhai Cc: Michal Hocko Cc: Mike Kravetz Cc: Naoya Horiguchi Cc: linux-man --- Link to relevant discussion: https://lore.kernel.org/linux-mm/1578993378-10860-2-git-send-email-lixinhai.lxh@gmail.com/ mm/mempolicy.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b2920ae..ec897d1 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -557,9 +557,10 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, unsigned long end, struct mm_walk *walk) { + int ret = 0; #ifdef CONFIG_HUGETLB_PAGE struct queue_pages *qp = walk->private; - unsigned long flags = qp->flags; + unsigned long flags = (qp->flags & MPOL_MF_VALID); struct page *page; spinlock_t *ptl; pte_t entry; @@ -571,16 +572,44 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask, page = pte_page(entry); if (!queue_pages_required(page, qp)) goto unlock; + + if (flags == MPOL_MF_STRICT) { + /* + * STRICT alone means only detecting misplaced page and no + * need to further check other vma. + */ + ret = -EIO; + goto unlock; + } + + if (!vma_migratable(walk->vma)) { + /* + * Must be STRICT with MOVE*, otherwise .test_walk() have + * stopped walking current vma. + * Detecting misplaced page but allow migrating pages which + * have been queued. + */ + ret = 1; + goto unlock; + } + /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ if (flags & (MPOL_MF_MOVE_ALL) || - (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) - isolate_huge_page(page, qp->pagelist); + (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) { + if (!isolate_huge_page(page, qp->pagelist) && + (flags & MPOL_MF_STRICT)) + /* + * Failed to isolate page but allow migrating pages + * which have been queued. + */ + ret = 1; + } unlock: spin_unlock(ptl); #else BUG(); #endif - return 0; + return ret; } #ifdef CONFIG_NUMA_BALANCING