From patchwork Thu Feb 13 02:07:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11379633 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 B17C41800 for ; Thu, 13 Feb 2020 02:09:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 677D3206DB for ; Thu, 13 Feb 2020 02:09:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mWjHfJ+7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 677D3206DB 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 A0C746B04F7; Wed, 12 Feb 2020 21:09:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9BD526B04F9; Wed, 12 Feb 2020 21:09:18 -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 8D1FC6B04FA; Wed, 12 Feb 2020 21:09:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 768566B04F7 for ; Wed, 12 Feb 2020 21:09:18 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3ACAC4410 for ; Thu, 13 Feb 2020 02:09:18 +0000 (UTC) X-FDA: 76483471596.14.pin45_6e3f9a3463448 X-Spam-Summary: 2,0,0,53cd6e217969259b,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:968:973:988:989:1260:1345:1437:1535:1544:1605:1711:1730:1747:1777:1792:2393:2559:2562:2693:2910:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4117:4250:4321:4605:5007:6121:6261:6653:7514:7875:7903:9413:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:13095:13153:13156:13228:14040:14096:14181:14394:14687:14721:21060:21080:21094:21323:21433:21444:21451:21627:21666:21795:21939:21990:30003:30012:30051:30054:30064:30070,0,RBL:209.85.128.67:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.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: pin45_6e3f9a3463448 X-Filterd-Recvd-Size: 6715 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Thu, 13 Feb 2020 02:09:17 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id a9so4810472wmj.3 for ; Wed, 12 Feb 2020 18:09:17 -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=PemMGzOpUHAyOrQBqw0/tPQ6XlJ6e8+AeiArgqBwNNw=; b=mWjHfJ+72lDIBR4E9gotUYHDr0V+c1zGOR80Nx5+a7rNbpdOaB+LZJy6ubBDMNDl6R Xu0SFN9s/7h5znxzLeqfztD0GlRZO7/WQeqIdEjFXLB7Eu+80fL7TA60BqX33nEICknv 1LNTMsKo/+vk+0yjG1qlKOg5iK24RDVJSY1XbvNb3/CdjuhOZiowhHEbyixWeLCYpofK zRPD0Uyrq64XDf53Px5E0X2Zz0H4rJtFNOKy8ZjqO3anKFXYQbsaIPyji5q+cZm3sKbJ 0BpsZjW8t3tbqWm6LkBYUQn36nQCsuaDmWtmNn3vcwDbNvxWozSpilWFR5gLltFYEw8n 2JGQ== 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=PemMGzOpUHAyOrQBqw0/tPQ6XlJ6e8+AeiArgqBwNNw=; b=nOWdHMwtzC8b/btxQBmKaPkSndrtT5kCLzEbtEM+mSn+xzaZY49cXMyXX8Wb6DuUfJ s7lhciTupkVSvAPFSc5BetSsCw76dhCj9W+7w6hsundd8NtAq1DbLK0pur2XiLfdXTUp 3Fe+PMSO6Gah3mCLJYThzEjF7mLeDmHvnvU5piHBtj2KBLu4k+8PwV/Xzfz/mFtNhJYB P1YjBGLNLNR+gjtbJGscMevwpc+hoITuHvgC/68rLMtAxTM163zRjpPeMkiTKJVi3Gwe PTMCvKxoRPvISBzU1Fam1bkIT+/H+PM0i+EfvLMadzgtLxFit7E2/xt4J2X3UC98nUx7 VaoA== X-Gm-Message-State: APjAAAVHrorRfbOZd8s0rXRJOFXODeu/6l8bo1/yPrPLJ3DCW6tEAdQF w9etJoyUPwguQYMO4hzQHAB7kjrO X-Google-Smtp-Source: APXvYqz2yi/bNOcFW8JMBcuRR2S/F/IzuHIHyLWLF5Ikw28Apkb59Zujx/WJ0zpSiCOrveGcvMJNaQ== X-Received: by 2002:a1c:9854:: with SMTP id a81mr2247454wme.1.1581559755868; Wed, 12 Feb 2020 18:09:15 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id r6sm838013wrq.92.2020.02.12.18.09.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Feb 2020 18:09:14 -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 v2] mm/mempolicy: support MPOL_MF_STRICT for huge page mapping Date: Thu, 13 Feb 2020 02:07:07 +0000 Message-Id: <1581559627-6206-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 to existing users: - If MPOL_MF_STRICT alone was previously used, hugetlb pages not following the memory policy would not cause an EIO error. After this change, hugetlb pages are treated like all other pages. If MPOL_MF_STRICT alone is used and hugetlb pages do not follow memory policy an EIO error will be returned. - 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 Reviewed-by: Mike Kravetz Reviewed-by: Naoya Horiguchi --- v1 -> v2: Revise the commit message(i.e., the first part about impaction) according to Mike. 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