From patchwork Tue May 14 13:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10942981 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 443851398 for ; Tue, 14 May 2019 13:17:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3194728555 for ; Tue, 14 May 2019 13:17:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25A6A286AE; Tue, 14 May 2019 13:17:08 +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=-2.9 required=2.0 tests=BAYES_00,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 AD26A28555 for ; Tue, 14 May 2019 13:17:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0849A6B000A; Tue, 14 May 2019 09:17:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 009246B000C; Tue, 14 May 2019 09:17:00 -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 E18316B000D; Tue, 14 May 2019 09:17:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 8C7EE6B000A for ; Tue, 14 May 2019 09:17:00 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id z13so3995582wrn.14 for ; Tue, 14 May 2019 06:17:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vA0P95K9fRheR4E+ESk+WXsmN1wAOY/rldukfhup8+8=; b=MDOj4Vgjgohm+4PiuCfRrIXBXv4LNsn1sun03j23vv/xyrTrB9aO+BPhRpRd5NKw0J nRTg8jOF5J909iQGHxDYDZ0EZRcClXiqUgt3/6jmIpRlHX2izCS4ZMXfoVZVv6KOMz4J Q6IiMh4URyrVhEzQ/iD3ZHDk8TS1NTs8NTPc4fZ0WEXdqxwpAEvxFwDf30XeEvGkFhLx qh0A7ZjDGUxxFfjBkcKtkU1eHpX8ttGtrHFD1juQbvW9qmr9ErHl3X6P91NxmesvqP1H YxiewVor/qbih14IWS9I6dgAoNhAedbAHVfeVYNU3S7LWNvCuoaRSPXHTX69KOP5yxJc AhfA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUQoTw0btkfV642D0dRL1je9IVxkXzRzIPC237tmpbNyhon7k6f O9Xi3UDgP7dm5bmRwuj5vvbkg2PhYgkSobPq2qNP4HnB5n675O1WCSUmxK8zMTRHdNtK1006xYc Czato/yKTzonYYA3RSoiC38wfpeNvI6glo/egxg2Uukikk6PRKMhHR5V5x1AnJUNFww== X-Received: by 2002:a5d:52cc:: with SMTP id r12mr21522399wrv.163.1557839819961; Tue, 14 May 2019 06:16:59 -0700 (PDT) X-Received: by 2002:a5d:52cc:: with SMTP id r12mr21522327wrv.163.1557839818628; Tue, 14 May 2019 06:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839818; cv=none; d=google.com; s=arc-20160816; b=BANEWZjRW+AyGPQI/l44nPNouoCKgodV7bbCwT+QJPaM9KnaFI8Svfy/aZbSbSBncI +TTA9HeO2hSs8YiPZT23Cih03+mUKrG2QkMcIm7pldqPyXmHyTaNZvnHs7DOdqTKrQi6 6XGWRPFcnHZ9Rc9euX+WiT/VhDYnp0hD4NYcPMCi2ByDn9EDFVKvA+sVKYe4oHihYNqR oAoUU4coqcFyN3e6wKLVoRIp3GRB14eksY0UkG/6ICUrAtjCtXaxaCzwpHVqAv6K/LZd VXtAkCtfmJ5SlKOu1rn6tJojCcty832DIzgRqPbomHI9CVS+vln1vPBY1Je5vHp/UcHE hy2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=vA0P95K9fRheR4E+ESk+WXsmN1wAOY/rldukfhup8+8=; b=adJarf9WzthDSHDzrKfkMzy9vR7sTPVkdN4wIrkTZPTpW5So2HYpTRzi54TLKM5HEt wWTxdHjWwRxtFI8Y7c8XG29Hy3ynltHVKUlZubu9ll9OXei9oPQctJBRQ86ZyLohoZcY wZXtDO1YGwAXg/eHZT5vcyGDE0HbLV7O60RltUe+5a2OMjNTG4V4ZJSH8cENiwMu2BH4 Y586luRJfvOKB1Jsnj/OYYNG96M0qRLUjpnXWn0o7vMpR08XW/tjbTkseVpV2E5KFJAC h91LOI0Pn0n5bpxV/L7Q+1mjEyumgunxxV13Iy+z+9OulQUIwKOISiG+ZfLLh0rUO29F Wyiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g8sor3132975wrm.43.2019.05.14.06.16.58 for (Google Transport Security); Tue, 14 May 2019 06:16:58 -0700 (PDT) Received-SPF: pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: APXvYqyA7ev1bORFUVmblymk/lrv+ZsAH07hD7NalfDAhNsPNHuNGBskFQiodfLrs4do1an3hLlNeQ== X-Received: by 2002:adf:c149:: with SMTP id w9mr10697762wre.40.1557839818301; Tue, 14 May 2019 06:16:58 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id b2sm16325220wrt.20.2019.05.14.06.16.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:16:57 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org Subject: [PATCH RFC v2 1/4] mm/ksm: introduce ksm_enter() helper Date: Tue, 14 May 2019 15:16:51 +0200 Message-Id: <20190514131654.25463-2-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514131654.25463-1-oleksandr@redhat.com> References: <20190514131654.25463-1-oleksandr@redhat.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: X-Virus-Scanned: ClamAV using ClamSMTP Move MADV_MERGEABLE part of ksm_madvise() into a dedicated helper since it will be further used for marking VMAs to be merged forcibly. This does not bring any functional changes. Signed-off-by: Oleksandr Natalenko --- mm/ksm.c | 60 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index fc64874dc6f4..02fdbee394cc 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2442,41 +2442,53 @@ static int ksm_scan_thread(void *nothing) return 0; } -int ksm_madvise(struct vm_area_struct *vma, unsigned long start, - unsigned long end, int advice, unsigned long *vm_flags) +static int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, + unsigned long *vm_flags) { - struct mm_struct *mm = vma->vm_mm; int err; - switch (advice) { - case MADV_MERGEABLE: - /* - * Be somewhat over-protective for now! - */ - if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE | - VM_PFNMAP | VM_IO | VM_DONTEXPAND | - VM_HUGETLB | VM_MIXEDMAP)) - return 0; /* just ignore the advice */ + /* + * Be somewhat over-protective for now! + */ + if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE | + VM_PFNMAP | VM_IO | VM_DONTEXPAND | + VM_HUGETLB | VM_MIXEDMAP)) + return 0; /* just ignore the advice */ - if (vma_is_dax(vma)) - return 0; + if (vma_is_dax(vma)) + return 0; #ifdef VM_SAO - if (*vm_flags & VM_SAO) - return 0; + if (*vm_flags & VM_SAO) + return 0; #endif #ifdef VM_SPARC_ADI - if (*vm_flags & VM_SPARC_ADI) - return 0; + if (*vm_flags & VM_SPARC_ADI) + return 0; #endif - if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) { - err = __ksm_enter(mm); - if (err) - return err; - } + if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) { + err = __ksm_enter(mm); + if (err) + return err; + } + + *vm_flags |= VM_MERGEABLE; + + return 0; +} - *vm_flags |= VM_MERGEABLE; +int ksm_madvise(struct vm_area_struct *vma, unsigned long start, + unsigned long end, int advice, unsigned long *vm_flags) +{ + struct mm_struct *mm = vma->vm_mm; + int err; + + switch (advice) { + case MADV_MERGEABLE: + err = ksm_enter(mm, vma, vm_flags); + if (err) + return err; break; case MADV_UNMERGEABLE: From patchwork Tue May 14 13:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10942983 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 2F4D21398 for ; Tue, 14 May 2019 13:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E0C92850F for ; Tue, 14 May 2019 13:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 124CA2864B; Tue, 14 May 2019 13:17:11 +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=-2.9 required=2.0 tests=BAYES_00,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 AB9E02850F for ; Tue, 14 May 2019 13:17:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ABE56B000C; Tue, 14 May 2019 09:17:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 786BD6B000D; Tue, 14 May 2019 09:17:02 -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 5887A6B000E; Tue, 14 May 2019 09:17:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 058266B000C for ; Tue, 14 May 2019 09:17:02 -0400 (EDT) Received: by mail-wm1-f72.google.com with SMTP id 206so721279wmb.0 for ; Tue, 14 May 2019 06:17:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ljDEI5wRVFawwIewIlFmLcuWyWda410CfkNvL+gmA1U=; b=ar9PFyI7d5vEd7kTsfwOcJmSGp63MBOUbZZqM0ijBfz5cg5rJHyO/xWWScwwSQgCSz Wd2JlBYMIuvL1gR4GPSjljDZk2BkgVRzpj9ZT9Vl78L/4wz/VvIQGwVQzmq3sphFuCdQ T+p18rnBHICFTLmDNXxERulyS/MvFyN/nrTvc+EciW/637dxonto6iDQUF5936F1Tokm PBjq2RlCKZjZFZ9P9x4tsRoSkoEeZs5wtc/PGdThyJmR6QieQVfa5WIfbCFbDxYJY9qr tR35gZiwTev/1mD0uh1Y7dLjtQgG/0qfPCd28ki24EtHKSRYBlcmQJv8NS1TdK4OsF3g TETg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUmMdD8wuWCA3FBf3ETTMCR/ghH8jb+/N/jV0ccJGU1qiqO4ywe doLHrD5UrhnOkX4CXbLPxNSMDVLLbkSbMsAPCAWdbigYUsvwcGKBW/UuG63gFBo9yfabe2Mc4yw 8AUtKph1RvkQcD/CqBoMphfFLaSKTlRgka4Y47/YZ/QJNhyHff52RpsKdexBFRH8LOw== X-Received: by 2002:a05:6000:43:: with SMTP id k3mr21866914wrx.234.1557839821551; Tue, 14 May 2019 06:17:01 -0700 (PDT) X-Received: by 2002:a05:6000:43:: with SMTP id k3mr21866837wrx.234.1557839820039; Tue, 14 May 2019 06:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839820; cv=none; d=google.com; s=arc-20160816; b=avWBEnCxV/sKUdjq+5WXyLkGKrv6VxloW6aDyB4zkeR1V2gzh70zDQj6W6GdwOd2b2 6zZt77A1T8fNIxgWUXY0Hk3B8aUAbLikT/JCRM+C5Vkv4YVZ7/FQrDwlkjSyJxJyjYvK 7S8N7PWTrNoraxlOR6xgYpSVe2qwMBQ5t+2vdXZFQw6OW77kK3EaYe9irK3PKI645hVY qBNmsamMCL70xD5m9CQF+t6iuHAHq/2O+iO8UFypAwWhC/n3kMy4U6wxFvPg8WwGI+eD wYAIhMzbqaVh57Uqufjrq+PX7ukXIpzJNsypl6ou2vhi9RdnVQO1ZigJkuShK7VoqHd9 KlVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ljDEI5wRVFawwIewIlFmLcuWyWda410CfkNvL+gmA1U=; b=eSdrU7cRmT4rMLpXKbDxcg+Nh+FuKFAsJFKGQdb6n6Qbd/GmOqks3yccUvYGatVAbo 3tUlfl+y0B3KSQU2Krjr4FPmv1FWcWdic0TvFItaGBWDrxa1cBp5GK+VE9nL3Qs/Klow NXEr9L9rdxWCPx2U0HXE3piBjK8NkMSiZA9fGLQTQpQeAabcIZspjpe1f3gDKSvzLMSe Jp76I/YTr/BPu0IgNHiRG6OmBglRTUDr/I+oofLa6RPx6gKVujRYgGZ2oHjkSA52ZSlE dmhG31Zp5nA8FgRffj8Jt6mEIR4vpuBj4IvYBvO+quInx978bCsqHc5uLNx3qq+UCSfg udZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 91sor3120573wrk.4.2019.05.14.06.16.59 for (Google Transport Security); Tue, 14 May 2019 06:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: APXvYqyoalSThS0pSE7N8sUVpxlOVAILQIDieoXie4XGja4UBj+IPrLGODtVhuz+nrtZqWL+oyjzXQ== X-Received: by 2002:adf:b35e:: with SMTP id k30mr2739640wrd.178.1557839819722; Tue, 14 May 2019 06:16:59 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id u125sm7196076wme.15.2019.05.14.06.16.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:16:59 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org Subject: [PATCH RFC v2 2/4] mm/ksm: introduce ksm_leave() helper Date: Tue, 14 May 2019 15:16:52 +0200 Message-Id: <20190514131654.25463-3-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514131654.25463-1-oleksandr@redhat.com> References: <20190514131654.25463-1-oleksandr@redhat.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: X-Virus-Scanned: ClamAV using ClamSMTP Move MADV_UNMERGEABLE part of ksm_madvise() into a dedicated helper since it will be further used for unmerging VMAs forcibly. This does not bring any functional changes. Signed-off-by: Oleksandr Natalenko --- mm/ksm.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 02fdbee394cc..e9f3901168bb 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2478,6 +2478,25 @@ static int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, return 0; } +static int ksm_leave(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long *vm_flags) +{ + int err; + + if (!(*vm_flags & VM_MERGEABLE)) + return 0; /* just ignore the advice */ + + if (vma->anon_vma) { + err = unmerge_ksm_pages(vma, start, end); + if (err) + return err; + } + + *vm_flags &= ~VM_MERGEABLE; + + return 0; +} + int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags) { @@ -2492,16 +2511,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, break; case MADV_UNMERGEABLE: - if (!(*vm_flags & VM_MERGEABLE)) - return 0; /* just ignore the advice */ - - if (vma->anon_vma) { - err = unmerge_ksm_pages(vma, start, end); - if (err) - return err; - } - - *vm_flags &= ~VM_MERGEABLE; + err = ksm_leave(vma, start, end, vm_flags); + if (err) + return err; break; } From patchwork Tue May 14 13:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10942985 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 9E1056C5 for ; Tue, 14 May 2019 13:17:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D6902850F for ; Tue, 14 May 2019 13:17:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80C4C28555; Tue, 14 May 2019 13:17:14 +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=-2.9 required=2.0 tests=BAYES_00,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 026972864B for ; Tue, 14 May 2019 13:17:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3CFE6B000D; Tue, 14 May 2019 09:17:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DF1546B000E; Tue, 14 May 2019 09:17:03 -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 C8ED96B0010; Tue, 14 May 2019 09:17:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 7DE4B6B000D for ; Tue, 14 May 2019 09:17:03 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id q16so9868073wrr.22 for ; Tue, 14 May 2019 06:17:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VdAVf6UsURaBN1kR2hvAUBFTDOMaklbC2zfjfZkKj2k=; b=Q1hqSdejAdasyyVkQGIVOxXWmpg29BmpQfR5oI7+XomefVfUcKC5BsIb8UK+vvwkM9 5xY3a1hO8Z4M+g4qxeWoV7cNFWxwroJSWujWB7FCVXTfg39aHxe1/4dbLxzkeyB0kiw5 x+NHa62WilyFW6U8FubAwQeG6lTgJe/eQD3mOjZLeLgEJFvaSsxSCE9a5lUS21OcARAU UzLFxF8fA3shHHLkE2Bh5ahN97QN3PqjGMBS9KqpJ4Ai0AXFVUiqGw0Kp36zBQuCo2Zm IHQ8cHK8zKMaTWKNrTT4aHVtk4UIGSg6UIPm1ygqblsBcL0MBQP1SqrsVFzB5tolKYep MRSA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWvPFM5ztjcL1PJtMnUPIN58HGDT6WgpbheyYmH2Katr12ewicO +vJdciBIGnT++e15FFvN4nMv+3mtxbzpKVeqDxNEHGt/TsFeQMSXfAEseCEBVTk1OjGSsa4b49Z Tu/0FZ0GdNdNDlrVmszOyNjt3XlgiHrNcygiPcn2hFuExgQFtEKjKBPvO6/OgmG11HA== X-Received: by 2002:a1c:65c3:: with SMTP id z186mr16737379wmb.93.1557839822950; Tue, 14 May 2019 06:17:02 -0700 (PDT) X-Received: by 2002:a1c:65c3:: with SMTP id z186mr16737308wmb.93.1557839821484; Tue, 14 May 2019 06:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839821; cv=none; d=google.com; s=arc-20160816; b=f2OiSu9XbL6UIg0/jkeIIF+DVd7XOnnn3DTE0aGXWHo2vXjsHqy7WHBKzY8vYYNGC+ Jy5nAJ+EleqbrZ9eA2lHrcyrODvD19jJ1vVtYcxp+w4iov0O9XP74cB3gQrvk6jAQqw4 XYHxBIoQXjpH+I5Ol2pyOch2ZzM0Zze8i80e7MBB4ApgzK6Vay9Sl9A2Xix0kYRTsnhL xTRs0tguliyrooufL8sqQ5fW1kjpBjd8u2cYBrtdAcD446+G4UyDQ0WT5/iruSktfQDh tuqQBrEjn4E1YcB91lxIRARLveFaPOeKUMHZCc1gkYndXyot66jaC5Sp0EbEc/ueiQOH 2jpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=VdAVf6UsURaBN1kR2hvAUBFTDOMaklbC2zfjfZkKj2k=; b=dUGstb8im/ZINFHDsT6jIHnioOgamqkHPKfRTDCbE4izgNZuO5oH74q4inWr8agqCg Zic1J/CVf4Vrq1PF6MKiB1NFftQefmdS+20Pv2Ua2sBpOHL4m89c9o9Mvu+Uqkwh074+ Lr5lNlCCe/oxH34QTSUwlfMLrTpILfWsEynGtLJkGa01JnpDNJvj7sJJj7ofZrTSoPr3 SL6xF710Imss1dC5eQ+Jdcs9MSVQW1f5R8HNl/XPJngCqL6afgsRJ6RfT5LePBBJOgwx 6fAKNylUXBzaP9QCGLUqz+fV3IGkfYe0ofHVbgksc0vM4mJ0reXDk7ppto2S9wMB6gyc WZBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w2sor3141214wrm.19.2019.05.14.06.17.01 for (Google Transport Security); Tue, 14 May 2019 06:17:01 -0700 (PDT) Received-SPF: pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: APXvYqyKKvVTOE8RaLl7n7pCLi0m5G1sMvqGxaeEklK4ZdRJocqbNZnJLuLQOOWk1SEOtgBgAe0hnw== X-Received: by 2002:adf:8306:: with SMTP id 6mr9923763wrd.155.1557839821146; Tue, 14 May 2019 06:17:01 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id f7sm1720014wmc.26.2019.05.14.06.17.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:17:00 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org Subject: [PATCH RFC v2 3/4] mm/ksm: introduce force_madvise knob Date: Tue, 14 May 2019 15:16:53 +0200 Message-Id: <20190514131654.25463-4-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514131654.25463-1-oleksandr@redhat.com> References: <20190514131654.25463-1-oleksandr@redhat.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: X-Virus-Scanned: ClamAV using ClamSMTP Present a new sysfs knob to mark task's anonymous memory as mergeable. To force merging task's VMAs, its PID is echoed in a write-only file: # echo PID > /sys/kernel/mm/ksm/force_madvise Force unmerging is done similarly, but with "minus" sign: # echo -PID > /sys/kernel/mm/ksm/force_madvise "0" or "-0" can be used to control the current task. To achieve this, previously introduced ksm_enter()/ksm_leave() helpers are used in the "store" handler. Signed-off-by: Oleksandr Natalenko Reviewed-by: Aaron Tomlin Reviewed-by: Timofey Titovets --- mm/ksm.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index e9f3901168bb..22c59fb03d3a 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2879,10 +2879,77 @@ static void wait_while_offlining(void) #define KSM_ATTR_RO(_name) \ static struct kobj_attribute _name##_attr = __ATTR_RO(_name) +#define KSM_ATTR_WO(_name) \ + static struct kobj_attribute _name##_attr = __ATTR_WO(_name) #define KSM_ATTR(_name) \ static struct kobj_attribute _name##_attr = \ __ATTR(_name, 0644, _name##_show, _name##_store) +static ssize_t force_madvise_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + pid_t pid; + bool merge = true; + struct task_struct *tsk; + struct mm_struct *mm; + struct vm_area_struct *vma; + + err = kstrtoint(buf, 10, &pid); + if (err) + return -EINVAL; + + if (pid < 0) { + pid = abs(pid); + merge = false; + } + + if (!pid && *buf == '-') + merge = false; + + rcu_read_lock(); + if (pid) { + tsk = find_task_by_vpid(pid); + if (!tsk) { + err = -ESRCH; + rcu_read_unlock(); + goto out; + } + } else { + tsk = current; + } + + tsk = tsk->group_leader; + + get_task_struct(tsk); + rcu_read_unlock(); + + mm = get_task_mm(tsk); + if (!mm) { + err = -EINVAL; + goto out_put_task_struct; + } + down_write(&mm->mmap_sem); + vma = mm->mmap; + while (vma) { + if (merge) + ksm_enter(vma->vm_mm, vma, &vma->vm_flags); + else + ksm_leave(vma, vma->vm_start, vma->vm_end, &vma->vm_flags); + vma = vma->vm_next; + } + up_write(&mm->mmap_sem); + mmput(mm); + +out_put_task_struct: + put_task_struct(tsk); + +out: + return err ? err : count; +} +KSM_ATTR_WO(force_madvise); + static ssize_t sleep_millisecs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -3185,6 +3252,7 @@ static ssize_t full_scans_show(struct kobject *kobj, KSM_ATTR_RO(full_scans); static struct attribute *ksm_attrs[] = { + &force_madvise_attr.attr, &sleep_millisecs_attr.attr, &pages_to_scan_attr.attr, &run_attr.attr, From patchwork Tue May 14 13:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10942989 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 0F46F1398 for ; Tue, 14 May 2019 13:17:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F130327F9F for ; Tue, 14 May 2019 13:17:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E598D28555; Tue, 14 May 2019 13:17:16 +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=-2.9 required=2.0 tests=BAYES_00,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 8EEA827F9F for ; Tue, 14 May 2019 13:17:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27CD76B000E; Tue, 14 May 2019 09:17:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 204C36B0010; Tue, 14 May 2019 09:17:05 -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 0F79B6B0266; Tue, 14 May 2019 09:17:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id B4A836B000E for ; Tue, 14 May 2019 09:17:04 -0400 (EDT) Received: by mail-wm1-f71.google.com with SMTP id y187so720843wmg.3 for ; Tue, 14 May 2019 06:17:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4NHszGXSdUYSHK5uiVaOzd/y+HHMtNL3fJ2rPoCVo3g=; b=XUAtjZS/9fzK+wy3QZxFQtKx7PjZvImbQ+7YVpByAcgua7iCFVW4Bge27fuXmclINO dSOfBrT3sKdx5GsWY2xGTvYvJ0Fp0enzuiPY/JXVTjm+zRDi/mnLeU5kpBYmADLkOJKK 2GMG6IH3MVvVNNSNZApiS2HzM78bq+GHICcXBTkfE+fFDskRx+rGpCjgvyJWll2YIGFQ DIzcqMTb0XPX4zZzhbNK/x8C4AyEXtnjRMVXUScLuqpsRYnK2dg7+PshdopOi4kVxYy6 LmCYxNxtCePeljoraj3QMouqo152gb2fnqWikthkoSanSJEAlulMdaBe/VQDrTRgGXGh G3Pg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWhS+/+00co5sX5T1Ej5j2sdN7CTr8T7WKL8ASEUTJ77VkP+0zh kL0LZKuHBAcBlefrTWl9dhvjYBU6q5RoYIN5t82bPZZN5AoOcbsWznB51J6E9R++Ta7VZjlx1wc Cr+zsLqy1vb8zWyIPJl/lUrdg9FOOSHSNB1u0Tw9/WY3f9azsnZKlWMtwCPpsJBrj6A== X-Received: by 2002:adf:eb89:: with SMTP id t9mr18116644wrn.109.1557839824149; Tue, 14 May 2019 06:17:04 -0700 (PDT) X-Received: by 2002:adf:eb89:: with SMTP id t9mr18116569wrn.109.1557839822917; Tue, 14 May 2019 06:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839822; cv=none; d=google.com; s=arc-20160816; b=kZ9h0U4Qn1DAduVcwTWx5BfZM28htZjuMQ9kCv2cr+5SYKYLMg1qu3Y58GGaPnagGL nfKkZNva5IkoZs3ByPWW+v2Ete8LuxvuvSCN7SRGf4MDEK5DOYg6xfteAF2v4wPvHV40 eppDaWS3Ma6RPLhywYjRmNNEX586OwlNPdWja4S3GN7VlIVBuk6ESRnCPyD8jrzG2eFO vPZo6wIbECwYY7j7wF+8jhAn5Yov3FEV9rI8QrzYL5g8+FRXqC41u5Hl76eopI1W9zqv r+OHJ2pw73ebAaXITUHlVDh/Kijw8GME0nf+sWVUEWLFhAW2/wkN1CS/iUv5cauylKbb FhUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=4NHszGXSdUYSHK5uiVaOzd/y+HHMtNL3fJ2rPoCVo3g=; b=Ek4B3MqyeqFE1uBVQpkNPmFPzVljqphT8afQHypHM9WKZlEA6yLc7WtQ9+qYBVZN9z l1Hs+B0UZkgh16QqrMCDjfWXo0HaqjVGQBXlmCY2hM+iQYONBZpJV0xG0azwrYFx2dHT Mx1anKefOmIgl1TpyupNf69uJNVMYwGk4DAOYOopuveFIVGlDujNWK1C6MDSG4JmKc3w sEzPxNSfcnS5uVBOTgnSbMdrbubCbQ8Fe78CnOPY03j0NIiSS6MN5SVHHmTfjatDhQJQ j3LdRC73tfQFMbSZGwHEvjWdbwcOLIPjh8DGmwQKc7xK7jvmWBmBmCOvv01vqe+iqfqc fSGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u7sor3088446wro.35.2019.05.14.06.17.02 for (Google Transport Security); Tue, 14 May 2019 06:17:02 -0700 (PDT) Received-SPF: pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of oleksandr@redhat.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=oleksandr@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Google-Smtp-Source: APXvYqz90MXu1Y+IegMsTYBwvQ7q04E4Nwy8CUaUfOYUksdQNjQvegVE/S1PVrMeC+cUogaaT3sQLA== X-Received: by 2002:adf:cd0d:: with SMTP id w13mr21219109wrm.38.1557839822566; Tue, 14 May 2019 06:17:02 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id o4sm3420247wmc.38.2019.05.14.06.17.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:17:01 -0700 (PDT) From: Oleksandr Natalenko To: linux-kernel@vger.kernel.org Cc: Kirill Tkhai , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , linux-mm@kvack.org Subject: [PATCH RFC v2 4/4] mm/ksm: add force merging/unmerging documentation Date: Tue, 14 May 2019 15:16:54 +0200 Message-Id: <20190514131654.25463-5-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190514131654.25463-1-oleksandr@redhat.com> References: <20190514131654.25463-1-oleksandr@redhat.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: X-Virus-Scanned: ClamAV using ClamSMTP Document respective sysfs knob. Signed-off-by: Oleksandr Natalenko Reviewed-by: Timofey Titovets --- Documentation/admin-guide/mm/ksm.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index 9303786632d1..4302b92910ec 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -78,6 +78,17 @@ KSM daemon sysfs interface The KSM daemon is controlled by sysfs files in ``/sys/kernel/mm/ksm/``, readable by all but writable only by root: +force_madvise + write-only control to force merging/unmerging for specific + task. + + To mark the VMAs as mergeable, use: + ``echo PID > /sys/kernel/mm/ksm/force_madvise`` + + To unmerge all the VMAs, use: + ``echo -PID > /sys/kernel/mm/ksm/force_madvise`` + (note the prepending "minus") + pages_to_scan how many pages to scan before ksmd goes to sleep e.g. ``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``.