From patchwork Tue Jul 30 05:23:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11064867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12B3C14E5 for ; Tue, 30 Jul 2019 05:23:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036E9285A4 for ; Tue, 30 Jul 2019 05:23:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBA1F285BD; Tue, 30 Jul 2019 05:23:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDC8E285B8 for ; Tue, 30 Jul 2019 05:23:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A7718E0005; Tue, 30 Jul 2019 01:23:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 430658E0002; Tue, 30 Jul 2019 01:23:18 -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 233CF8E0005; Tue, 30 Jul 2019 01:23:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id DF9B78E0002 for ; Tue, 30 Jul 2019 01:23:17 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id f2so34579044plr.0 for ; Mon, 29 Jul 2019 22:23:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=LjmLHqeEBIcPM1EzxLLHUMjC3IQ3Iyup262DaJYHDoM=; b=B9z+kUg4+Txs5I5DlfrAtwihiYdLhEDvxUAjY08DIcVpbmsUXlNOL+6N8soF55sLzy 1Fg93GOH1L2UBt0VfwBbx1YijnaQndFmYABW+yUJZ4M8K4bC/z44cw2dkrABGZ/OdJwv quzmxvjOoEelSUMwz/QcsbjaZSbQ5RvQjk4zFbT8mdk84cOTafI2GJxKo527MX1dxq0h QzczI96T0RoqxQyTiarcnv5FmogpU9oGi1ZMmRlwxRN2xt7wiEKA5XdPt1NehOcWVsE3 4AH+8/lLWyBLM+n9ZHVf1UUYId9bmV6EB9loR+vERAp/gS0TkbxZMDkwjWh3pwOxI0Ah K9mQ== X-Gm-Message-State: APjAAAVY4aBj+uBoPde0HMf6vNBjF86aWHfyzX/CRKzxs/Cu3l9sU6eh 14dEdR/oQ4BhXMH20uN0vPq4PX0kvDPqIzkUQlfFEcXLSj8OK4WhWQUPAvPaFOnsVRhGconVe2S qluR8W/YGpC+2Z9d8+7d2Fs8aDRj67NxlQcQoDf/9GkcSu9eIxaywRdaPSNVtQFjwMA== X-Received: by 2002:a62:1ac9:: with SMTP id a192mr265765pfa.260.1564464197602; Mon, 29 Jul 2019 22:23:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyElYYtctg0cQda5kcYYfwWAVecDQKXVWhUGv5fblag15y10MHOAIBwicqkPnJ3DAapghln X-Received: by 2002:a62:1ac9:: with SMTP id a192mr265738pfa.260.1564464196972; Mon, 29 Jul 2019 22:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564464196; cv=none; d=google.com; s=arc-20160816; b=TgDJxM1EGQN9UbyL66/5U0Xu053lV+0iFE+UTDfg0xukZe7txLyUoRuQKBG74EzhGW uM2aR9WySxZkcl1hAW6hrj+5aI0HkUrwPRoJUNgYgtME2kLRx+gqOb9uHLKHjbPjDzPu tzTkVevW9mJkGT9pIm0Sm3kyv3J8omXD6ZUPbDv3T4hdFQb56HEKA6Rzb5IWP+UKNlOU pwqUBJOMbZDgy39QxfMhhzi5KjAk5cX9RdS+qsP+qt+2QNVhNKn1OzIM7RchsBiQ1K6m ambN+pSQKLdzHfjrAp/GdDvYJkpZu5QNa03W0LaTOZz3ka3THMnYQym1gXFRUpnzOVmK Ovcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=LjmLHqeEBIcPM1EzxLLHUMjC3IQ3Iyup262DaJYHDoM=; b=JKbBGQRuXWMS4l/6MjCNNUs09pRl0QivGIPJXdITpN8XQxRcX/svb4mjKay7Z59gTN V3dQrtLWD+WZgRAc2YqgCTIOqX5BXcREaGkUEIY49iLSiwafZhgRO8EU9n2uM8262AF4 tB3QTfn60yKvo0SleVIEfsaeSMOioaztwjVvI2NcyTTNnLlvKDXxrt5RMhxLYmGwd0Mx yC+b6aVLwKvvj/7Bla1c5KgKPJI/4JUBcJXEYHIWb6DH/qVSGInDO4GkAAap66y7R47S ESvaYQV9ujpb4FnmP+7CmGIe9Tkup+9J3SmxFylNfO+xN1NGLlmXz2pX4JBFuXp+OCUg oZyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=FZ8sYBoX; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com. [67.231.145.42]) by mx.google.com with ESMTPS id g5si25610195pjp.71.2019.07.29.22.23.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 22:23:16 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.145.42 as permitted sender) client-ip=67.231.145.42; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=FZ8sYBoX; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.145.42 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U5NGvE007601 for ; Mon, 29 Jul 2019 22:23:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=LjmLHqeEBIcPM1EzxLLHUMjC3IQ3Iyup262DaJYHDoM=; b=FZ8sYBoX1zYxSfEM8Uw9qs+wcIdA9UYk6UGgoYdqGW7UnZoweZCeVEOTe7wbBCH1LzB8 g4N5ojVnHFY8EpM4RdU7A5ZcxyLwwPhXr/fv7wd5MGvFW4+A3gnTzZyME4Jduw0djfPb RUF/kdizCk8DHkQX8nUILEhA4PXDAvUBEHc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2u2f53r2wf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 29 Jul 2019 22:23:16 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 29 Jul 2019 22:23:15 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id BEC1E62E2FF0; Mon, 29 Jul 2019 22:23:14 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v10 1/4] mm: move memcmp_pages() and pages_identical() Date: Mon, 29 Jul 2019 22:23:02 -0700 Message-ID: <20190730052305.3672336-2-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190730052305.3672336-1-songliubraving@fb.com> References: <20190730052305.3672336-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-30_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=971 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300056 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP This patch moves memcmp_pages() to mm/util.c and pages_identical() to mm.h, so that we can use them in other files. Acked-by: Kirill A. Shutemov Signed-off-by: Song Liu --- include/linux/mm.h | 7 +++++++ mm/ksm.c | 18 ------------------ mm/util.c | 13 +++++++++++++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0334ca97c584..f189176dabed 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2891,5 +2891,12 @@ void __init setup_nr_node_ids(void); static inline void setup_nr_node_ids(void) {} #endif +extern int memcmp_pages(struct page *page1, struct page *page2); + +static inline int pages_identical(struct page *page1, struct page *page2) +{ + return !memcmp_pages(page1, page2); +} + #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */ diff --git a/mm/ksm.c b/mm/ksm.c index 3dc4346411e4..dbee2eb4dd05 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1029,24 +1029,6 @@ static u32 calc_checksum(struct page *page) return checksum; } -static int memcmp_pages(struct page *page1, struct page *page2) -{ - char *addr1, *addr2; - int ret; - - addr1 = kmap_atomic(page1); - addr2 = kmap_atomic(page2); - ret = memcmp(addr1, addr2, PAGE_SIZE); - kunmap_atomic(addr2); - kunmap_atomic(addr1); - return ret; -} - -static inline int pages_identical(struct page *page1, struct page *page2) -{ - return !memcmp_pages(page1, page2); -} - static int write_protect_page(struct vm_area_struct *vma, struct page *page, pte_t *orig_pte) { diff --git a/mm/util.c b/mm/util.c index e6351a80f248..0d5e2f425612 100644 --- a/mm/util.c +++ b/mm/util.c @@ -783,3 +783,16 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen) out: return res; } + +int memcmp_pages(struct page *page1, struct page *page2) +{ + char *addr1, *addr2; + int ret; + + addr1 = kmap_atomic(page1); + addr2 = kmap_atomic(page2); + ret = memcmp(addr1, addr2, PAGE_SIZE); + kunmap_atomic(addr2); + kunmap_atomic(addr1); + return ret; +} From patchwork Tue Jul 30 05:23:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11064869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1F1213A0 for ; Tue, 30 Jul 2019 05:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2373285A4 for ; Tue, 30 Jul 2019 05:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C682C285BD; Tue, 30 Jul 2019 05:23:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35B9C285A4 for ; Tue, 30 Jul 2019 05:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AEBE8E0006; Tue, 30 Jul 2019 01:23:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 039598E0002; Tue, 30 Jul 2019 01:23:23 -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 DF37B8E0006; Tue, 30 Jul 2019 01:23:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id B9F038E0002 for ; Tue, 30 Jul 2019 01:23:23 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id b22so48610228yba.4 for ; Mon, 29 Jul 2019 22:23:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=QlY0qULqwL/0inVNzJF/uiGiPZ28zpDBxtshMYBqHLY=; b=TmkFHYnkkyWwJ1gcAzgOK8Io2GkEmSYzscGttXHUWd8NEgJ2zcU5YbGP3bOi4jQ2qO HKEmHFTHGbznyCEl3V3stHhNwHhGupnaYDcSStU0IVzNsunKoZzDpl/rJdWw6Y2nL5TG iXY0QedDd1MjqPiUfkeQPDLBrFuTDh7LYXHpyXZotnDaEiCalLJCc+drGZz2UdEM3RAU yq8z4Xas6PJv3lRdvXVWOHAr+JGdv3Dtko5/oROlQkDxf5kG5bKmfmVKhF5pwX2RuYAv MYOR8Ot+NhsGllH2OENAhp4FCRILY4zsjVw+xvLri+W9rZnE44B5nbQ6JPsYZwiXvYfe BkvA== X-Gm-Message-State: APjAAAVcIzWjxYCcNL37soHNpG9bKE0+cOkHUpfh0l5hS88/sCtSN01D cbevrYwQyQw+QW4IaKyMWl/8FiKw9nOCXZJuHq8Pgt4vGqNcOQRsdBzzVJDU+oO2SKHA+6jeyOy ooqrBCYSCWoZzzEynfI7/TehIChSk/mwKz5ZEYxtoDseT5ENiiHW40Qy+rjpAGG4MEQ== X-Received: by 2002:a25:1584:: with SMTP id 126mr50555060ybv.102.1564464203330; Mon, 29 Jul 2019 22:23:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy07fqsDHwQGkzb5iIMomZmwX/O9cBMHCJ2gb/ZdfmK/SVHtQwmezAZ8ns2TaEUoIgUdKE6 X-Received: by 2002:a25:1584:: with SMTP id 126mr50555032ybv.102.1564464202404; Mon, 29 Jul 2019 22:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564464202; cv=none; d=google.com; s=arc-20160816; b=UPG3S9nUuGNnAJOzxN+ka1qMNU6bxUo/HDIk+WNRyxRntRx6n9QCefpTfhgSBVbsCy QxYVzZ69eC2QTQt1y+m5TGzYaZsI/dbJZ8N6F36zbYzBP+g+UxvDL7eSoOSb004DnUrV jJK6EfCqLfNUQzjOV0JFwteDPEoaEeI96MykHOPUrdPV/jBaw1axidcI89nxjAM6/tqE BZvPvf4ne6G6N3OX06dN6IvssWuYPRbvP7l/j+LDy0AefErgfmPs7hphwZiyd/NS709T 8rY73wpxT6kIT08aeQ6Z8/qz5p10iKF6euNbNis7c3lOrKYi0iCtuVEu0/TmBsBnrNan Zz3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=QlY0qULqwL/0inVNzJF/uiGiPZ28zpDBxtshMYBqHLY=; b=hqPEEipkel3PepP8BIx5++s2Kiv+JzuMdBiVRxchTisCPSdYu7WPcXZvBf6n0z4UkC Kl437o8T8B1zf8grWeVv26pHX4GbgZFnw3L/YcHlYmps/+H23JPSqRwDivafpAGiTCBm RqJMZE2SI0JrOFnpdnyYAeQh8gqZreIHar6efeHGFBL/cysqarFJrsm4xl2CxFRjToVZ oX/Bg3REDgDG3iyl2Hd4uX9ivULwA3PTutOQGO1X2uA+mxJWD14iclUsNr45FcRMyGhS yYvwnPQdwQXNaEqcvc5jLqh6VzWJNRYwZ5CRgz6MixOpcenJSh4fLtcjFIl+di27kejW NLfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=QKFOLy2h; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id x15si16403417ybq.238.2019.07.29.22.23.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 22:23:22 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=QKFOLy2h; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U5MSXu011167 for ; Mon, 29 Jul 2019 22:23:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=QlY0qULqwL/0inVNzJF/uiGiPZ28zpDBxtshMYBqHLY=; b=QKFOLy2hzgA8Rq8Q4/CD1W46KzCXyv/J7Jdnwm9AFaj1uLYghPpleofLCCsg7QZmveXY oGo7nhzS0iR0dwbknp//DsY/qe52tM4ztvnr1CsUcZ7XBz7i0Wntj60vX8Nmn5nLelu3 WnzqKfDdcMyH/6JbSAM3O77oN+Br/LATsD4= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 2u260g9x66-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 29 Jul 2019 22:23:21 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Mon, 29 Jul 2019 22:23:20 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 4A35E62E2FF0; Mon, 29 Jul 2019 22:23:18 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v10 2/4] uprobe: use original page when all uprobes are removed Date: Mon, 29 Jul 2019 22:23:03 -0700 Message-ID: <20190730052305.3672336-3-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190730052305.3672336-1-songliubraving@fb.com> References: <20190730052305.3672336-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-30_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=884 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300056 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP Currently, uprobe swaps the target page with a anonymous page in both install_breakpoint() and remove_breakpoint(). When all uprobes on a page are removed, the given mm is still using an anonymous page (not the original page). This patch allows uprobe to use original page when possible (all uprobes on the page are already removed). As suggested by Oleg, we unmap the old_page and let the original page fault in. Suggested-by: Oleg Nesterov Signed-off-by: Song Liu --- kernel/events/uprobes.c | 66 +++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 84fa00497c49..648f47553bff 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -143,10 +143,12 @@ static loff_t vaddr_to_offset(struct vm_area_struct *vma, unsigned long vaddr) * * @vma: vma that holds the pte pointing to page * @addr: address the old @page is mapped at - * @page: the cowed page we are replacing by kpage - * @kpage: the modified page we replace page by + * @old_page: the page we are replacing by new_page + * @new_page: the modified page we replace page by * - * Returns 0 on success, -EFAULT on failure. + * If @new_page is NULL, only unmap @old_page. + * + * Returns 0 on success, negative error code otherwise. */ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, struct page *old_page, struct page *new_page) @@ -166,10 +168,12 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, VM_BUG_ON_PAGE(PageTransHuge(old_page), old_page); - err = mem_cgroup_try_charge(new_page, vma->vm_mm, GFP_KERNEL, &memcg, - false); - if (err) - return err; + if (new_page) { + err = mem_cgroup_try_charge(new_page, vma->vm_mm, GFP_KERNEL, + &memcg, false); + if (err) + return err; + } /* For try_to_free_swap() and munlock_vma_page() below */ lock_page(old_page); @@ -177,15 +181,20 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, mmu_notifier_invalidate_range_start(&range); err = -EAGAIN; if (!page_vma_mapped_walk(&pvmw)) { - mem_cgroup_cancel_charge(new_page, memcg, false); + if (new_page) + mem_cgroup_cancel_charge(new_page, memcg, false); goto unlock; } VM_BUG_ON_PAGE(addr != pvmw.address, old_page); - get_page(new_page); - page_add_new_anon_rmap(new_page, vma, addr, false); - mem_cgroup_commit_charge(new_page, memcg, false, false); - lru_cache_add_active_or_unevictable(new_page, vma); + if (new_page) { + get_page(new_page); + page_add_new_anon_rmap(new_page, vma, addr, false); + mem_cgroup_commit_charge(new_page, memcg, false, false); + lru_cache_add_active_or_unevictable(new_page, vma); + } else + /* no new page, just dec_mm_counter for old_page */ + dec_mm_counter(mm, MM_ANONPAGES); if (!PageAnon(old_page)) { dec_mm_counter(mm, mm_counter_file(old_page)); @@ -194,8 +203,9 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, flush_cache_page(vma, addr, pte_pfn(*pvmw.pte)); ptep_clear_flush_notify(vma, addr, pvmw.pte); - set_pte_at_notify(mm, addr, pvmw.pte, - mk_pte(new_page, vma->vm_page_prot)); + if (new_page) + set_pte_at_notify(mm, addr, pvmw.pte, + mk_pte(new_page, vma->vm_page_prot)); page_remove_rmap(old_page, false); if (!page_mapped(old_page)) @@ -488,6 +498,10 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, ref_ctr_updated = 1; } + ret = 0; + if (!is_register && !PageAnon(old_page)) + goto put_old; + ret = anon_vma_prepare(vma); if (ret) goto put_old; @@ -501,8 +515,30 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, copy_highpage(new_page, old_page); copy_to_page(new_page, vaddr, &opcode, UPROBE_SWBP_INSN_SIZE); + if (!is_register) { + struct page *orig_page; + pgoff_t index; + + VM_BUG_ON_PAGE(!PageAnon(old_page), old_page); + + index = vaddr_to_offset(vma, vaddr & PAGE_MASK) >> PAGE_SHIFT; + orig_page = find_get_page(vma->vm_file->f_inode->i_mapping, + index); + + if (orig_page) { + if (PageUptodate(orig_page) && + pages_identical(new_page, orig_page)) { + /* let go new_page */ + put_page(new_page); + new_page = NULL; + } + put_page(orig_page); + } + } + ret = __replace_page(vma, vaddr, old_page, new_page); - put_page(new_page); + if (new_page) + put_page(new_page); put_old: put_page(old_page); From patchwork Tue Jul 30 05:23:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11064871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE0F813A0 for ; Tue, 30 Jul 2019 05:23:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8FD285BD for ; Tue, 30 Jul 2019 05:23:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3911285A4; Tue, 30 Jul 2019 05:23:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985BA285A4 for ; Tue, 30 Jul 2019 05:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E3AF8E0007; Tue, 30 Jul 2019 01:23:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 36C198E0002; Tue, 30 Jul 2019 01:23:28 -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 233768E0007; Tue, 30 Jul 2019 01:23:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id F0FCC8E0002 for ; Tue, 30 Jul 2019 01:23:27 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id h203so46742306ywb.9 for ; Mon, 29 Jul 2019 22:23:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=YpPGU3ZiU++0VQgyDS3QSdQ0lQHIOIN4ED9AD9AHh/Y=; b=ToMS4ghTZn42SOJliwVuSHguQJcKyQgoTBC9Jft7BnqaEYLqlC4ovmCD0m2sOzNa25 uNsmA0GbcUVRw6t706e4zWExOFNsAwEjO0qLyocFIHff2JkVUxFxdV1a9FIRqVJ5QLia xiJ7f3gUJrDQKBZj5tiihgWgHB6RlBZqhcqNb4pMlWjeOtgfVbH7UcVa6fE1K/UJUuD1 sLypEkh0k9ZmYH+WNYBgAYRs0KRsXNvDoe+5EUYxXIDA7aYB3zEQqiKZUJgeFoapNhAh P8IgGeg4xUsTgx6USvEI2nQEApgC67un1OKzBx8UmM0gwPRUmvgc3DFb++p+V8Ggpsdy jamQ== X-Gm-Message-State: APjAAAU2HW9lWHw8rzitx9WCRD+bLYivATT7BQS9fHKOfNANbsUw3pnO 5ZAYY+C0TnjcwPCKH3cuzQSTA1HUZHR14iaZFMWpUOarTnw2O0WqYpvL2uXPZAX90E3zM6QeuOK eS6N9es4TQMZWUIwIUuvb6CPhyCAeEzdmvpJffrwNdkExw1Vl2tTw4Hk19pNk3wP5BQ== X-Received: by 2002:a81:9b8e:: with SMTP id s136mr73013332ywg.114.1564464207659; Mon, 29 Jul 2019 22:23:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlVlRdVjoyRtq2z6yu3wEXhB42PL7NKuT0Y0i7xXDZcblv5izKPaD/X3HtDwqG1B+uOn35 X-Received: by 2002:a81:9b8e:: with SMTP id s136mr73013314ywg.114.1564464207032; Mon, 29 Jul 2019 22:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564464207; cv=none; d=google.com; s=arc-20160816; b=KzVxsqZGiGMBqUfSSp3lvBp0Tf+hM9HHKXRtQTP4DHSo2UgGvjX+ExXV6IzScipChk A4jR6AAtK58Lr41RFgp1vymB0QjS0D+jBZMfgXGh5nVwkdoWr5g3qwk62GYyZ3nMmz0v ehPf/QajonqWb7cdmrESCaDFYs767ewUiOteXwEJb+fkYvlILqR6Ef3HLjbOz7ThPgfn C02KOsYx4G24DdTZ77JredB+u9BUitvxG9SGHCzi0Sst7EKmt4Ruv4MeXzI2pyy7DFvu y94O7XdOJkRaujf9oQMBaGZIj/IgMeoAE075YxmgJ8UR5YED3PRxRTc682+ZrEM/RwA9 fAPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=YpPGU3ZiU++0VQgyDS3QSdQ0lQHIOIN4ED9AD9AHh/Y=; b=jvX/DCHTcTIDtggOcytXRH/uffA5i9Hiyr2oIE5ZzVVbLFi+pAOGphdfeXh/UT9IsK 5f3MAWULW3mPlQ/A0tWt/MvrjypKmYWm8LaHrR8Onf6graWb1+73JiWdaCFMlKS9vsfm qK7G2qVBd+9IzNy+1DOkUXxnlIDCeyI7WfU4IjgnHxEqQyuwNIiNt1c0ri0D9B6UPUE5 7EdxAmcxYl8QFkP4Ve6KjmhJ3Dw468MPbdPoesBdGhk2ykkJOXRwmxSlrWxN3sFHzpSG 9HvQzSPjAtpA/KDm1lyNPGFV7QkIkOtI40AKn9gkPNz7Po2cOCZoq5O3jvobIKpX8Elz 2teA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="mu1ySjw/"; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id q195si24768274ybg.339.2019.07.29.22.23.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 22:23:27 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="mu1ySjw/"; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U5JAgP001064 for ; Mon, 29 Jul 2019 22:23:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=YpPGU3ZiU++0VQgyDS3QSdQ0lQHIOIN4ED9AD9AHh/Y=; b=mu1ySjw/kbTmhP5vRfEKL8I9vZPwH5AJPB64Yuj7PIVtwKVfOuBGKkFvD9WcYT15Y6Yv u5Q9iC4QQsqvoemsDexIz5UoLroNpi5oRsT5dz4mvh7bQx5so6G+LGP+0mgOqKeAT1st v0r7aD6F+c5D6G1UsPbKjNDFGLqm42SPP7s= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2u2eqgr4vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 29 Jul 2019 22:23:26 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Mon, 29 Jul 2019 22:23:25 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id B584662E2FF0; Mon, 29 Jul 2019 22:23:22 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v10 3/4] mm, thp: introduce FOLL_SPLIT_PMD Date: Mon, 29 Jul 2019 22:23:04 -0700 Message-ID: <20190730052305.3672336-4-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190730052305.3672336-1-songliubraving@fb.com> References: <20190730052305.3672336-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-30_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300055 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP This patches introduces a new foll_flag: FOLL_SPLIT_PMD. As the name says FOLL_SPLIT_PMD splits huge pmd for given mm_struct, the underlining huge page stays as-is. FOLL_SPLIT_PMD is useful for cases where we need to use regular pages, but would switch back to huge page and huge pmd on. One of such example is uprobe. The following patches use FOLL_SPLIT_PMD in uprobe. Acked-by: Kirill A. Shutemov Signed-off-by: Song Liu --- include/linux/mm.h | 1 + mm/gup.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f189176dabed..74db879711eb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2614,6 +2614,7 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, #define FOLL_COW 0x4000 /* internal GUP flag */ #define FOLL_ANON 0x8000 /* don't do file mappings */ #define FOLL_LONGTERM 0x10000 /* mapping lifetime is indefinite: see below */ +#define FOLL_SPLIT_PMD 0x20000 /* split huge pmd before returning */ /* * NOTE on FOLL_LONGTERM: diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..3c514e223ce3 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -399,7 +399,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, spin_unlock(ptl); return follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); } - if (flags & FOLL_SPLIT) { + if (flags & (FOLL_SPLIT | FOLL_SPLIT_PMD)) { int ret; page = pmd_page(*pmd); if (is_huge_zero_page(page)) { @@ -408,7 +408,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, split_huge_pmd(vma, pmd, address); if (pmd_trans_unstable(pmd)) ret = -EBUSY; - } else { + } else if (flags & FOLL_SPLIT) { if (unlikely(!try_get_page(page))) { spin_unlock(ptl); return ERR_PTR(-ENOMEM); @@ -420,6 +420,10 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, put_page(page); if (pmd_none(*pmd)) return no_page_table(vma, flags); + } else { /* flags & FOLL_SPLIT_PMD */ + spin_unlock(ptl); + split_huge_pmd(vma, pmd, address); + ret = pte_alloc(mm, pmd); } return ret ? ERR_PTR(ret) : From patchwork Tue Jul 30 05:23:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11064873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9242013AC for ; Tue, 30 Jul 2019 05:23:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A1D285A4 for ; Tue, 30 Jul 2019 05:23:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 757E3285BD; Tue, 30 Jul 2019 05:23:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0081B285A4 for ; Tue, 30 Jul 2019 05:23:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA6E78E0008; Tue, 30 Jul 2019 01:23:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D56658E0002; Tue, 30 Jul 2019 01:23:36 -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 BF86F8E0008; Tue, 30 Jul 2019 01:23:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id 9A04D8E0002 for ; Tue, 30 Jul 2019 01:23:36 -0400 (EDT) Received: by mail-yw1-f71.google.com with SMTP id l141so46692925ywc.11 for ; Mon, 29 Jul 2019 22:23:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:smtp-origin-hostprefix:from :smtp-origin-hostname:to:cc:smtp-origin-cluster:subject:date :message-id:in-reply-to:references:mime-version; bh=+zWjU0C6LD6HpRrP4wreVSMF6ug2Y3cK0xwApLG5ZA4=; b=SklugcSyNdLF+fCeVBF7/NBFGoPfh6FPluknV359NBwi1hKIQp1atlWpMxtdEIwl5l TIZGqOJuQw1XzxKZxYXffKh0AxtOmPXFeomdPxTAlC9IaXt6e6KyDqrakjHaEQeFoTso 58jQY+zoacQAuSBFLcodoHMOT3BtM5rpOm2fb54+il+kzU6keLk5QCP/XM8zNlCMV3SH 1wPiFkbuK0BCB35bUsyhXym6lvjVdeqIPnwBMg+5C3f/SBaMNzaauVOfjJFJx8+Y7M6Y an6ePkinfaiHlBJM8QC/MCJv3U9dw6cIyEDr3wO8jSpUdfLgFQ5Y8lDKjGGRM25iUdtU bWcw== X-Gm-Message-State: APjAAAXRYFygKVaVemxxOhiF0xyBzcuOy2ogTAeO9p+MXowRA+/MywOX /oGmFFRpfWrpeBtFWnLZAHGZLzpcQ18KLVQYpYX+QggMB8k3tA6yQCEfF+edpRAGPHH0GczLzzQ fj/87+AXhKMZX3nvXc7D0UXRAmaOTUNjXf2utQQGZ/Ct4cuhjr+bgGzExOPpzN8GE/Q== X-Received: by 2002:a81:3d7:: with SMTP id 206mr64570703ywd.411.1564464216396; Mon, 29 Jul 2019 22:23:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3znVuaujYJRX5CWYyvYQfbcz1msYh0LR8lWYMEFpxgrEbxC4CL9FlBSJGnd++XXVN5/pv X-Received: by 2002:a81:3d7:: with SMTP id 206mr64570690ywd.411.1564464215862; Mon, 29 Jul 2019 22:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564464215; cv=none; d=google.com; s=arc-20160816; b=wjylkJWyrIBYkG65WU0+veP8NHxCFYDsitm0EP17mZbXQiRmkG8aZMTtqdka8/Zwse phFZGfm9em2FWrmLu6X4Lz0HKTzDMdY9bNFRNqg8gdvAk6CxarBcGa5BKGNXNEUeBPp+ 5jhjkWKjPjCxBA9UKcWotNtuOQ3bVEjDEf9AfBs5r26FnEkwMJ0Q0B5RCuNll0zNscSj xA9vOeLFQE8rptPxbAeXQ/TksWW4jk3l1To6wbGmwoTh3z/HDtDPBln98C360HaPxVbr tWfMEJOu46LFoZTE8Aidj8gMOTJt1TMHfeh+likd4o5zPgWjkhxy1V2hEqIJKCokRFkv VkRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=+zWjU0C6LD6HpRrP4wreVSMF6ug2Y3cK0xwApLG5ZA4=; b=OvxUtyTCZeipJFO43oZn06wauvWzv/9jR/AnlSEXI9yGhVRSsdbKjG+loJm1Vj4ilo lmF5m5d0wmIlUuezf+Qu9daKVEFKY6K0CdQYObIojsNCdyVcK9ofLJK2YWQk8/dgDQ41 AM7uwqixzn+IBUc9Lycb2H8IJWZojZC8Tufpi3xUvLgK3NEyCjzXxw3psXaGfSbrgpMT KyYINtcTZui4cZSlB1ZwwNDLzPigKq5jcbBA2e8PnjHcM2NwCaumg4a1AO+IX0d5lnMj bfL0HVMoE5/ryCOAMVUwnSCPEmo+4TCZA/pcTj3sXPlJBQ55sDEwynQWL2lwy+9yQDtz 1Lrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=UbU4pV0W; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id x18si16014245ybs.101.2019.07.29.22.23.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 22:23:35 -0700 (PDT) Received-SPF: pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) client-ip=67.231.153.30; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=UbU4pV0W; spf=pass (google.com: domain of prvs=31148e3214=songliubraving@fb.com designates 67.231.153.30 as permitted sender) smtp.mailfrom="prvs=31148e3214=songliubraving@fb.com"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x6U5NWPO009788 for ; Mon, 29 Jul 2019 22:23:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=+zWjU0C6LD6HpRrP4wreVSMF6ug2Y3cK0xwApLG5ZA4=; b=UbU4pV0W3DxRWEaix/W2co//eu5KlKLS2m1VkOsi0GL2xPlA2eBds9vqvxXaOnJl6ZK/ 5gjj6EaJwgtu1vn19XtMDjo4BlPzJde+muZDfGqKIXn9cqNJV8DNnPJGeCmtFsAyidHR YG4lkGx0ik2CAyHfxZYrzX4QAUtqekPyhR4= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by m0089730.ppops.net with ESMTP id 2u234ku0np-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 29 Jul 2019 22:23:35 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Mon, 29 Jul 2019 22:23:27 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 4162862E2FF4; Mon, 29 Jul 2019 22:23:26 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v10 4/4] uprobe: use FOLL_SPLIT_PMD instead of FOLL_SPLIT Date: Mon, 29 Jul 2019 22:23:05 -0700 Message-ID: <20190730052305.3672336-5-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190730052305.3672336-1-songliubraving@fb.com> References: <20190730052305.3672336-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-30_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=771 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300056 X-FB-Internal: deliver 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: X-Virus-Scanned: ClamAV using ClamSMTP This patch uses newly added FOLL_SPLIT_PMD in uprobe. This preserves the huge page when the uprobe is enabled. When the uprobe is disabled, newer instances of the same application could still benefit from huge page. For the next step, we will enable khugepaged to regroup the pmd, so that existing instances of the application could also benefit from huge page after the uprobe is disabled. Acked-by: Kirill A. Shutemov Reviewed-by: Srikar Dronamraju Signed-off-by: Song Liu --- kernel/events/uprobes.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 648f47553bff..27b596f14463 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -155,7 +155,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, { struct mm_struct *mm = vma->vm_mm; struct page_vma_mapped_walk pvmw = { - .page = old_page, + .page = compound_head(old_page), .vma = vma, .address = addr, }; @@ -166,8 +166,6 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, mm, addr, addr + PAGE_SIZE); - VM_BUG_ON_PAGE(PageTransHuge(old_page), old_page); - if (new_page) { err = mem_cgroup_try_charge(new_page, vma->vm_mm, GFP_KERNEL, &memcg, false); @@ -481,7 +479,7 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, retry: /* Read the page with vaddr into memory */ ret = get_user_pages_remote(NULL, mm, vaddr, 1, - FOLL_FORCE | FOLL_SPLIT, &old_page, &vma, NULL); + FOLL_FORCE | FOLL_SPLIT_PMD, &old_page, &vma, NULL); if (ret <= 0) return ret;