From patchwork Fri Dec 16 19:45:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13075344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8188C3DA6E for ; Fri, 16 Dec 2022 19:45:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 555748E0005; Fri, 16 Dec 2022 14:45:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 417C98E0001; Fri, 16 Dec 2022 14:45:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 292558E0005; Fri, 16 Dec 2022 14:45:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 16ED68E0001 for ; Fri, 16 Dec 2022 14:45:48 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DB2D3411C9 for ; Fri, 16 Dec 2022 19:45:47 +0000 (UTC) X-FDA: 80249199534.26.AFE8A5F Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf12.hostedemail.com (Postfix) with ESMTP id 6A11240009 for ; Fri, 16 Dec 2022 19:45:46 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=T4TW14IB; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf12.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671219946; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8xPO0qZD4VwfQbdayhIhCXlDmSs3MHLtJoBHL/+lYXU=; b=Ys3q/b0a+/ClIn6ttqsu76u4gUR0rvgpOS8sJd0nfpUhVMz9S6s1ZNmk0eP2P29MFhKfoA IKojAITsixThvsN+FBmvj1mFADv5k9NsYYeGBAn8QvHkFiRUeAF4z1NqCg09mJodkT0swi GSLT/5uxlI6CFVmy/9RT6TYRXsE5znA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=T4TW14IB; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf12.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671219946; a=rsa-sha256; cv=none; b=bnbeNyxMW/U/E2JCxIMCPQ+kCbFtXcBYuVXRjn/GYGTRuMi6zpteLOVZYe4AIl868ul10R BQORIpbS1mrTqkl122Y8e+6lB6p9NDvSN7/+oPs7KTiNN7qXitDwcspGIC982qO3EyDCkV DTc7dpywWQliE6bDewzI3Xumyt/Aab4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1671219945; bh=C3x0LxEaOZxc8RC+32bOB5QAmF9xMZLVglOZu0jV2nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4TW14IBwDykxKAdOJEumQDzYo81Fj7dUn/WD8Lb8OJcFIsOrRessQxWLDlr0n76e 4hUv8PS4ZUKS3k5+7NrLSV8sBMSdsaoBMwrxGl2KPgn2Rjf714stlIsd8Glw49SsRr Y5jlZPBIE+030hCcSRO50IAk8RYgBTB20BU1bWCIE20rjPaoyA8c4lPceOJD+R6Ngj UiC54cy7oC8KhtYbCzPfNvN5vcnVeODmQ/S/uELtnDclvN4DM+T6fOkBodobyrV4IA 0RrXJ2FGJhyWn+XRPLHkIgcIb5peu/0SxC/SH5d65MbxBuMFKBgSCTlEohCmvWSi7B 7Xx3ML+O0xqdg== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4NYfj51zpjzbGl; Fri, 16 Dec 2022 14:45:45 -0500 (EST) From: Mathieu Desnoyers To: linux-mm@kvack.org Cc: Michal Hocko , Mathieu Desnoyers , "Aneesh Kumar K . V" , Dave Hansen , Feng Tang , Michal Hocko , Andrea Arcangeli , Mel Gorman , Mike Kravetz , Randy Dunlap , Vlastimil Babka , Andi Kleen , Dan Williams , Huang Ying , linux-api@vger.kernel.org, Andrew Morton Subject: [PATCH 2/2] mm/mempolicy: do not duplicate policy if it is not applicable for set_mempolicy_home_node Date: Fri, 16 Dec 2022 14:45:37 -0500 Message-Id: <20221216194537.238047-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221216194537.238047-1-mathieu.desnoyers@efficios.com> References: <20221216194537.238047-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6A11240009 X-Stat-Signature: 37gndq74s6qajj7zqyawtw7tnxmmdbdi X-HE-Tag: 1671219946-903898 X-HE-Meta: U2FsdGVkX1/ZykSSzEVELR57dnzenGbdfWWPuAbD261Gf8xMJSp7Rsp4GFFqblPs9LJEAmZZXjKZt8wI3e7zC7hkTd/kpwap8RA72BPzvKOv0Ywbk884GjWE+I/sDFwL+3NY9Fpwfe/4XuxGoKH9mcycx5hIX3juhGoA2zakBYNDP/PZjmygRQrLSysmDhxBIxFPqnTzox0ZIqzqZma2I2+lbnzckFZ1G46C2O7xreeoYn0PAwsdld4l7fD9gfgN/rd0FZOqiiV6pQ+BumHZy8MW6CIcHoJFkyronF0VwsOkHw6s/k866qO0sIn3f2tszbZYwgkAR3Virtg4F0Mj4QwAtlr5JxGoLtXXcFT44WPl725pOvKiCWnaESO81w8RslRIF+6NCLJuFv7raGpR6ZGzyCXScjwblBfSt0eEX1aVz7echYnndr13R0F63qtrU+tuq4iyt1GUY/48hVRYYRf7BP0H6hTKi/vKxpArJlDC3G1a6R5kbWhO7J7zomuTN2/hv+RtA8iPLQ0wcdh/R94QAskEq56KFcb+PyVxZntg/kr7tGy4D0kALvnarexlezr9h2OqrOcsoU8lbyhbwuaqnzZ4ZDC820PfKJ5fLlmQf31/1AAIDVZVQhkxMIMs7D/Q2exaoZW40TUrk7Vxoe2oLFQOcHPRhMj6mQRexHPWND4TZbWKXOphQPN98gdKhBWdJH87U/xtqZ52g1vuau7F+yWNZxJNt7xzxtRcH5vW77V1wQKxlZgrySm5aiDOxUF4xdk4GlyizdI+SKNsTF7dEIzoGrqfW34Y/+FHzJsAKzO2bYZdGHqRDfapyWHWJZBugp8h7CzT1Zm2FYrN99W3kqTVw1v/MBqZf6sYxzskEoCbwEUjhnNAIZqtMUSibZtU4B9m9impj55N8B9kVrZPqAW+5NdeTxA8drGrhfAk6SBT3c3kc3GzrcKOxXerHWzy53+P+ggJL+Q95g7 krNIe8jc EanQC4rhccjFygf9jTnGMVl+Yif+m5oKe5da7 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: From: Michal Hocko set_mempolicy_home_node tries to duplicate a memory policy before checking it whether it is applicable for the operation. There is no real reason for doing that and it might actually be a pointless memory allocation and deallocation exercise for MPOL_INTERLEAVE. Not a big problem but we can do better. Simply check the policy before acting on it. [ Mathieu: compile-tested only. Tested-by would be welcome. ] Signed-off-by: Michal Hocko Reviewed-by: Mathieu Desnoyers Signed-off-by: Mathieu Desnoyers Cc: Aneesh Kumar K.V Cc: Dave Hansen Cc: Feng Tang Cc: Michal Hocko Cc: Andrea Arcangeli Cc: Mel Gorman Cc: Mike Kravetz Cc: Randy Dunlap Cc: Vlastimil Babka Cc: Andi Kleen Cc: Dan Williams Cc: Huang Ying Cc: linux-api@vger.kernel.org Cc: Andrew Morton Cc: linux-mm@kvack.org --- mm/mempolicy.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 02c8a712282f..becf41e10076 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1489,7 +1489,7 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le { struct mm_struct *mm = current->mm; struct vm_area_struct *vma; - struct mempolicy *new; + struct mempolicy *new, *old; unsigned long vmstart; unsigned long vmend; unsigned long end; @@ -1521,31 +1521,27 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le return 0; mmap_write_lock(mm); for_each_vma_range(vmi, vma, end) { - vmstart = max(start, vma->vm_start); - vmend = min(end, vma->vm_end); - new = mpol_dup(vma_policy(vma)); - if (IS_ERR(new)) { - err = PTR_ERR(new); - break; - } - /* - * Only update home node if there is an existing vma policy - */ - if (!new) - continue; - /* * If any vma in the range got policy other than MPOL_BIND * or MPOL_PREFERRED_MANY we return error. We don't reset * the home node for vmas we already updated before. */ - if (new->mode != MPOL_BIND && new->mode != MPOL_PREFERRED_MANY) { - mpol_put(new); + old = vma_policy(vma); + if (!old) + continue; + if (old->mode != MPOL_BIND && old->mode != MPOL_PREFERRED_MANY) { err = -EOPNOTSUPP; break; } + new = mpol_dup(old); + if (IS_ERR(new)) { + err = PTR_ERR(new); + break; + } new->home_node = home_node; + vmstart = max(start, vma->vm_start); + vmend = min(end, vma->vm_end); err = mbind_range(mm, vmstart, vmend, new); mpol_put(new); if (err)