From patchwork Fri May 10 07:21:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10938301 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 5749A933 for ; Fri, 10 May 2019 07:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4031128A80 for ; Fri, 10 May 2019 07:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 345ED28BFC; Fri, 10 May 2019 07:21:34 +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 B378228A80 for ; Fri, 10 May 2019 07:21:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D62556B000D; Fri, 10 May 2019 03:21:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D124B6B000E; Fri, 10 May 2019 03:21:31 -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 B8D5D6B0010; Fri, 10 May 2019 03:21:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 9CE3D6B000D for ; Fri, 10 May 2019 03:21:31 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id v6so4656543qkh.6 for ; Fri, 10 May 2019 00:21:31 -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=qzOAoH/TNvXjcpwg8Oz/fc8MXlS07T4EqVnD2ZBjw6A=; b=gHEmxrY79UwqtOAk+N8ZqK5ukD4vjuW6HBFxTrhijR5+EhpXoAP2c+KSJk1++p3Urr sFOubgBdzjzWs7jYUSJWvx4MtOkEQsxziVvG6yBlDZR0cY0jZckbux/mAfNJ4nXeQfCQ IRttGIZc2ocUmzAJTgD9tUfSJCRqek/D9ABmYBetrdhhZmwQQHbextL7IGWRNm4L3MB4 G8PPtcx609H19tSqD0UPdIs18gA7oDYC1EqSfoQgiYdug/mdqEj0KZZ0HC9UZbW/t+yp Jy5IJypINpVlnlDqrNzW3wArlRxnHaWhNz2vCmjya2iVhzqR/Vaxwu5PYpNQH7CDvbE2 VR3A== 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: APjAAAWllIRN8MBTVpx+3SfIXBHvvB7O97YjtquKy9OfR9t6KS5C+SuQ Lmqt3gu0SvICzCB+S+yLi9BN+BOV3C9+a/DqV/lQ3y3askl0MMTCxIIa8mOQ0FG3HFgI16vttar 5XLTgiZok24/XMa1CZkAy2Ook5m8dUBxpb3QPJ7e2/ZmCmv7zkqQcIG+27x2Kk4g7Tw== X-Received: by 2002:a37:7986:: with SMTP id u128mr7720409qkc.45.1557472891393; Fri, 10 May 2019 00:21:31 -0700 (PDT) X-Received: by 2002:a37:7986:: with SMTP id u128mr7720341qkc.45.1557472890051; Fri, 10 May 2019 00:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557472890; cv=none; d=google.com; s=arc-20160816; b=Zod5Ci/alJVH8kmSGfPBSR2ufJuyg61zieb1AYu/42leqVgTIz4enitsTGJNiBReiV yxTIBA1+wOkFVrz7KYO0y6DeidH1lEb+sOGxcGgBOw0rc9yC7VJmOBkfnnVBtpUq6A2g c+g1mClUxorlXshpNYPFru5CRMMS8TFptEnEuhF59Hg5bnSmVe5jLtC9NVmlRueHNDJe tntoaxOLUpK86sIaRnFjxK6yLpwtd0NtQ4WDYjtfISQ1vtVp+PZrkZJbl+Wlky/zO+X3 aivRv9XAWguz89tw+KaVqu+6YcavWH03UosfXQPmzJCMLHZfDYcYa9K3ujl+K3xU81LA nsuw== 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=qzOAoH/TNvXjcpwg8Oz/fc8MXlS07T4EqVnD2ZBjw6A=; b=M6JY73i/3Y+2QLkg2UopPGPr/c8JPqzHCTVykyILzPvw4dprBRTAXvZlZ3yL/5BqCd Npqeh46o6Koi2PlV4kEpBML+KhCCsR/uj5BtdpYHUSb3mupfr+AQ2S9Efz7egQJ6YfmI 5ncLbj/LvO7Ep678S1vW0jgPmoHsxcbLBgamg6f5X6EMDRRsa5rawkAvr3NyFiS+qxxi uwuuDWZoObE3bk78sla6Op1Stq/eid1038SN6EexGPAX8pAEHnH3R/U4jEpJAItY88hj FZyPc8PliaLDADn8nNoBOcgQDNpZb9MtizExodGPn2I4bMSNSiFZOIfCQ1Sy2ZTkkHA9 z8vw== 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 j124sor2459245qkc.24.2019.05.10.00.21.30 for (Google Transport Security); Fri, 10 May 2019 00:21:30 -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: APXvYqwKpqIkvTy6CiBwHKtkH71OJTdUzb+Ov2Uf7B01EGgr+mZM24+4w2juFKcB1sGHGd3S+eq7hw== X-Received: by 2002:a37:648d:: with SMTP id y135mr7656118qkb.237.1557472889756; Fri, 10 May 2019 00:21:29 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id i92sm2579667qtb.44.2019.05.10.00.21.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 May 2019 00:21:29 -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 , linux-mm@kvack.org Subject: [PATCH RFC 1/4] mm/ksm: introduce ksm_enter() helper Date: Fri, 10 May 2019 09:21:22 +0200 Message-Id: <20190510072125.18059-2-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190510072125.18059-1-oleksandr@redhat.com> References: <20190510072125.18059-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 in do_anonymous_page(). This does not bring any functional changes. Signed-off-by: Oleksandr Natalenko --- include/linux/ksm.h | 2 ++ mm/ksm.c | 66 ++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index e48b1e453ff5..bc13f228e2ed 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -21,6 +21,8 @@ struct mem_cgroup; #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); +int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, + unsigned long *vm_flags); int __ksm_enter(struct mm_struct *mm); void __ksm_exit(struct mm_struct *mm); diff --git a/mm/ksm.c b/mm/ksm.c index fc64874dc6f4..a6b0788a3a22 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2450,33 +2450,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, 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 */ - - if (vma_is_dax(vma)) - return 0; - -#ifdef VM_SAO - if (*vm_flags & VM_SAO) - return 0; -#endif -#ifdef VM_SPARC_ADI - 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; - } - - *vm_flags |= VM_MERGEABLE; + err = ksm_enter(mm, vma, vm_flags); + if (err) + return err; break; case MADV_UNMERGEABLE: @@ -2496,6 +2472,42 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, return 0; } +int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, + unsigned long *vm_flags) +{ + int err; + + /* + * 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; + +#ifdef VM_SAO + if (*vm_flags & VM_SAO) + return 0; +#endif +#ifdef VM_SPARC_ADI + 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; + } + + *vm_flags |= VM_MERGEABLE; + + return 0; +} + int __ksm_enter(struct mm_struct *mm) { struct mm_slot *mm_slot; From patchwork Fri May 10 07:21:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10938303 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 5002913AD for ; Fri, 10 May 2019 07:21:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3861928A80 for ; Fri, 10 May 2019 07:21:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C79028BFC; Fri, 10 May 2019 07:21:37 +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 983BD28A80 for ; Fri, 10 May 2019 07:21:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 043BE6B000E; Fri, 10 May 2019 03:21:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F0E676B0010; Fri, 10 May 2019 03:21:33 -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 E24E46B0266; Fri, 10 May 2019 03:21:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id BFC586B000E for ; Fri, 10 May 2019 03:21:33 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id z34so5360368qtz.14 for ; Fri, 10 May 2019 00:21:33 -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=vOejBc1QN8TJ6K5lhz+Yvn4+87eApSQ46e32YrdputU=; b=OTa8DO/9iURQRMDXomZs18mb2peGLR9ksUo49ijwFsmdHL1+okuwJ8of/2WKwVpVXK A/AybugSZj6u7CLS7Aj5GqX4pjYtCPDHcSwXA7xIiZcn0l1h6zdBJQUGO2MfRUdpnkAX 3w0eziynKl18nAwLQtGMv/s8IWvEDAGBRJDSOHBQzDGkGaV6eLbk9HqTCqccwcZWXHIj woSu2LQrvZ2bgvBjcXcC78mwUrdyNn3l50lfFwGq0f2P8Q8nn/ler45fkBvn0MNemd8f ZacSosao4heC1JQpJFNyD0PrRjn78Enwt2DUMa7bMIqIkcwrXQ29y4Mmcofv0R0UJr03 VGlA== 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: APjAAAWFm2mJH73xtcJW9D217dmwRPLmRJOtz0eZ+o5YopAcLrxhmIlB 37s+Dr7T43FjX5lckj6xxZYANlG/N+rXwyQSDK8OMqfFRqBrOCfljsbQXcarOqocJoD562hMrXL f+wJbDCsobJ58m7d/QRkxwMGDRZ98u180iyHIwhKPzr7e28TAsefBwSq8+RKwCOm8RA== X-Received: by 2002:ac8:1931:: with SMTP id t46mr8128884qtj.170.1557472893540; Fri, 10 May 2019 00:21:33 -0700 (PDT) X-Received: by 2002:ac8:1931:: with SMTP id t46mr8128823qtj.170.1557472892307; Fri, 10 May 2019 00:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557472892; cv=none; d=google.com; s=arc-20160816; b=0H9Re5N6K5TUrh4o28TCvYNshYggXMpbjzzIpIUCV3q//D2Ah9HsRIXtfK7tgjZ/pA EJDLRfNiQDvHpm88KOV80qn4SK4DrfrRpSZ6QXJG2bIzjkriYDY0owrVCSB1pQkq0Zb8 vhUPyzJcqUtqIGsDlD4Oaq0pO7QbEkSo0Sb8OeuuTeypJnvHUPgtLbUUsmsBbaTxuFyM VA1AXpfjsjD+JfrfpnNTfEwBuEXZ6AnTVy3gLYHeH5yK5DhLBD/8Kn2Hlj/fjEkQLBL0 BJU3xrT+bEsNKpfqo3DUOaWcy+wrKtzHh7TS51CJzFU0f6RwC9yemjbTRFj0lTDnhBTN +zVQ== 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=vOejBc1QN8TJ6K5lhz+Yvn4+87eApSQ46e32YrdputU=; b=VY5N38FJdzx2A+Z9um20yWskBeZ69K31r0MBk1iEo9MNu3xkHCYBFHnjjGSoCfvBaY jIjwy9lJIY3/Y4muSmp/Bas5F5reDgBzXLjVT4stblzQdAbAl3HqcHeCYqRl4CyLcgub bslPPmvXxXkiam+d6J45aSeV8iOPSp+PwPAjLHFLEevS8v8YMJUrGZTtRkR/s/yA9vVn WcUztaASjWoDTfM5DCvgjPttXBfPzGkWTwiS4hYKpzv1WHjPFrCHEiHfJ9XaXp0tvEKl 0xUX6to7hI2RTpkaYSaDZ1yTyOCgbrv4fXJ2vJsmkojf9LgCirrffGWhl6itZTyovq+X 6CIg== 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 m135sor2567975qke.42.2019.05.10.00.21.32 for (Google Transport Security); Fri, 10 May 2019 00:21:32 -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: APXvYqzPe26b8EbsZNX43wXIk/ZJMwyIsrlo41vyylWWI/zUIYOTf4fWR2vuKOPN9vH/HO0FjC5SPg== X-Received: by 2002:a37:5444:: with SMTP id i65mr7490671qkb.263.1557472892023; Fri, 10 May 2019 00:21:32 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id y18sm2145077qty.78.2019.05.10.00.21.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 May 2019 00:21:31 -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 , linux-mm@kvack.org Subject: [PATCH RFC 2/4] mm/ksm: introduce VM_UNMERGEABLE Date: Fri, 10 May 2019 09:21:23 +0200 Message-Id: <20190510072125.18059-3-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190510072125.18059-1-oleksandr@redhat.com> References: <20190510072125.18059-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 Add separate vmaflag to allow applications to opt out of automatic VMAs merging due to (possible) security concerns. Since vmaflags are tight on free bits, this flag is available on 64-bit architectures only. Thus, subsequently, KSM "always" mode will be available for 64-bit architectures only as well. Signed-off-by: Oleksandr Natalenko --- fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 6 ++++++ include/trace/events/mmflags.h | 7 +++++++ mm/ksm.c | 13 +++++++++++++ 4 files changed, 29 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 95ca1fe7283c..19cc246000e8 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -648,6 +648,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_MIXEDMAP)] = "mm", [ilog2(VM_HUGEPAGE)] = "hg", [ilog2(VM_NOHUGEPAGE)] = "nh", +#ifdef VM_UNMERGEABLE + [ilog2(VM_UNMERGEABLE)] = "ug", +#endif [ilog2(VM_MERGEABLE)] = "mg", [ilog2(VM_UFFD_MISSING)]= "um", [ilog2(VM_UFFD_WP)] = "uw", diff --git a/include/linux/mm.h b/include/linux/mm.h index 6b10c21630f5..114cdb882cdd 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -252,11 +252,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */ +#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0) #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1) #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2) #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3) #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) +#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5) #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #ifdef CONFIG_ARCH_HAS_PKEYS @@ -272,6 +274,10 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef VM_HIGH_ARCH_5 +#define VM_UNMERGEABLE VM_HIGH_ARCH_5 /* Opt-out for KSM "always" mode */ +#endif /* VM_HIGH_ARCH_5 */ + #if defined(CONFIG_X86) # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ #elif defined(CONFIG_PPC) diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index a1675d43777e..717e0fd9d2ef 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -130,6 +130,12 @@ IF_HAVE_PG_IDLE(PG_idle, "idle" ) #define IF_HAVE_VM_SOFTDIRTY(flag,name) #endif +#ifdef VM_UNMERGEABLE +#define IF_HAVE_VM_UNMERGEABLE(flag,name) {flag, name }, +#else +#define IF_HAVE_VM_UNMERGEABLE(flag,name) +#endif + #define __def_vmaflag_names \ {VM_READ, "read" }, \ {VM_WRITE, "write" }, \ @@ -161,6 +167,7 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ {VM_MIXEDMAP, "mixedmap" }, \ {VM_HUGEPAGE, "hugepage" }, \ {VM_NOHUGEPAGE, "nohugepage" }, \ +IF_HAVE_VM_UNMERGEABLE(VM_UNMERGEABLE, "unmergeable" ) \ {VM_MERGEABLE, "mergeable" } \ #define show_vma_flags(flags) \ diff --git a/mm/ksm.c b/mm/ksm.c index a6b0788a3a22..0fb5f850087a 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2450,12 +2450,18 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, switch (advice) { case MADV_MERGEABLE: +#ifdef VM_UNMERGEABLE + *vm_flags &= ~VM_UNMERGEABLE; +#endif err = ksm_enter(mm, vma, vm_flags); if (err) return err; break; case MADV_UNMERGEABLE: +#ifdef VM_UNMERGEABLE + *vm_flags |= VM_UNMERGEABLE; +#endif if (!(*vm_flags & VM_MERGEABLE)) return 0; /* just ignore the advice */ @@ -2496,6 +2502,10 @@ int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, if (*vm_flags & VM_SPARC_ADI) return 0; #endif +#ifdef VM_UNMERGEABLE + if (*vm_flags & VM_UNMERGEABLE) + return 0; +#endif if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) { err = __ksm_enter(mm); @@ -3173,6 +3183,9 @@ static ssize_t full_scans_show(struct kobject *kobj, KSM_ATTR_RO(full_scans); static struct attribute *ksm_attrs[] = { +#ifdef VM_UNMERGEABLE + &mode_attr.attr, +#endif &sleep_millisecs_attr.attr, &pages_to_scan_attr.attr, &run_attr.attr, From patchwork Fri May 10 07:21:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10938305 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 977E7933 for ; Fri, 10 May 2019 07:21:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80E5228A80 for ; Fri, 10 May 2019 07:21:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7576B28BFC; Fri, 10 May 2019 07:21:39 +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 E058628A80 for ; Fri, 10 May 2019 07:21:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8E86B0010; Fri, 10 May 2019 03:21:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 96A416B0269; Fri, 10 May 2019 03:21: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 833B76B026A; Fri, 10 May 2019 03:21:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 62FEB6B0010 for ; Fri, 10 May 2019 03:21:36 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id h16so4639336qke.11 for ; Fri, 10 May 2019 00:21:36 -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=mlMuZ+baS9vhQtlkYflvWcBmyvS2Oox5GVM3xd9Ae4c=; b=biuQiSe+Nld0dzatZU9m/JYNwP4bABaybzvCsy6dCI4vdGn1PqrpFnK5EhLqkt8VEs GnnltG6frN+JIRQo8GWrxc1jGe3xh3GdxwS5Z+K1EADGvivV3ndnU/pltCt1v08l8M+c MtIKl/R0gawqHWqXrUjyHMkeHG0pFVcg4zqFnYRbsV0R+Bnns3/3dV7x1+w/wJQclgos leYgQ+NzmB1vxel67zN1ut0/uTPwMMK+Lq2pWbidePnHWIWFdRlXC//9VZMg8T2NN/ek ZyXLVEAXXprvsR2n2ItN5i28IatqbSSmDUaMcMkcufKYvj3pe+0sWJD4EruHUl/f+N// Lfxg== 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: APjAAAUOABhqRcoBpV4hmmhgHeVSvGkTarXgrcPX9ZXtjYDmZ0U0ALEE BjaKhdAHJ5Hs7QGK3kJyIWn/S43A0BzOh3byS9dLU+zR3fDcrQiszA2xN9NP8C9bgk8GMRgbZg/ ZLrxn9d2cUZ6BysIlcMWasZr7xQbnB8EIjYZpNmR1WS/6c0EQBzZvH3zYzp/LJJ5sUg== X-Received: by 2002:ac8:3702:: with SMTP id o2mr8012560qtb.119.1557472896106; Fri, 10 May 2019 00:21:36 -0700 (PDT) X-Received: by 2002:ac8:3702:: with SMTP id o2mr8012497qtb.119.1557472894928; Fri, 10 May 2019 00:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557472894; cv=none; d=google.com; s=arc-20160816; b=hmO7SH84wDWeyIpicWGazIyliYcTN7LneEMbdXmXP4eXr/j+xH5o6SiCR1BNc89zNG uX9IsPgj6DmajIxMhMoo6IUCAgns5k6NiwprUHXUUOoVicZhTiG5QQ2P/IDWE3x5e02t LG29Vipjncjibu+HbFF4UVm9xo6nvxYTqCiYeYOiXvGeBFNWvx+priLcNynhIHk+c7m3 7Lqz6kHmAwwm2zoRjgslgQL3mxOgh6tiN7fDmyVSMOPQzvZcILvY0FhRHbaDZBnfHFQU OJV2/FjsSfSnwCSfxGWrbDy/bJlxDsnAywmqHJkc8YDqPlt7Ew6ZolaIMMCDk8Z77jWv qCtw== 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=mlMuZ+baS9vhQtlkYflvWcBmyvS2Oox5GVM3xd9Ae4c=; b=TaKIvCVlxrY+q+253Ep5RJe9LP94wYZ5IUK4pZPdLCF/NPXMrxAedSc+w16P6PhKLL EC4hepi+2yUU5L62lmfEdXA+e4a67s8dOjAkSdseduHIqm0swU1h0XTQCTMYF5i2d4lO PMPAjCQjaQ0Xwjo7pi6No0VMUz+7uGErmeDGFn198Eh+7uC1VkFo5b9zSAxTB8dtiQ0q 0AEw/DM6s5V2f/tXhnb5/5l0Plif6dSUgFZzspdbI924870NW3Lyz37HgYH7DDI+bDj2 Z87rG3IO+Ue5oMiZUxWb+ldFzd/IJtMgogINzvJR8mekTn+Gan0jAfeO/G/H8f2qP2D5 O3VA== 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 s29sor3539250qve.49.2019.05.10.00.21.34 for (Google Transport Security); Fri, 10 May 2019 00:21:34 -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: APXvYqz/+ynrCsQP/BLl+LKcOs3x84+6OIoUVWb8hO3FNCiBMNoBPIf1oHQue0SdB9Zjhf1ZT6HdwQ== X-Received: by 2002:a0c:b28e:: with SMTP id r14mr7753580qve.158.1557472894619; Fri, 10 May 2019 00:21:34 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 124sm1641385qkj.59.2019.05.10.00.21.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 May 2019 00:21:33 -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 , linux-mm@kvack.org Subject: [PATCH RFC 3/4] mm/ksm: allow anonymous memory automerging Date: Fri, 10 May 2019 09:21:24 +0200 Message-Id: <20190510072125.18059-4-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190510072125.18059-1-oleksandr@redhat.com> References: <20190510072125.18059-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 Introduce 2 KSM modes: * madvise, which is default and maintains old behaviour; and * always, in which new anonymous allocations are marked as eligible for merging. The mode is controlled either via sysfs or via kernel cmdline for VMAs to be marked as soon as possible during the boot process. Previously introduced ksm_enter() helper is used to hook into do_anonymous_page() and mark each eligible VMA as ready for merging. This avoids introducing separate kthread to walk through the task/VMAs list. Signed-off-by: Oleksandr Natalenko --- include/linux/ksm.h | 3 +++ mm/ksm.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ mm/memory.c | 6 +++++ 3 files changed, 74 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index bc13f228e2ed..3c076b35259c 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -21,6 +21,9 @@ struct mem_cgroup; #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); +#ifdef VM_UNMERGEABLE +bool ksm_mode_always(void); +#endif int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long *vm_flags); int __ksm_enter(struct mm_struct *mm); diff --git a/mm/ksm.c b/mm/ksm.c index 0fb5f850087a..6a2280b875cc 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -295,6 +295,12 @@ static int ksm_nr_node_ids = 1; static unsigned long ksm_run = KSM_RUN_STOP; static void wait_while_offlining(void); +#ifdef VM_UNMERGEABLE +#define KSM_MODE_MADVISE 0 +#define KSM_MODE_ALWAYS 1 +static unsigned long ksm_mode = KSM_MODE_MADVISE; +#endif + static DECLARE_WAIT_QUEUE_HEAD(ksm_thread_wait); static DECLARE_WAIT_QUEUE_HEAD(ksm_iter_wait); static DEFINE_MUTEX(ksm_thread_mutex); @@ -2478,6 +2484,36 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, return 0; } +#ifdef VM_UNMERGEABLE +bool ksm_mode_always(void) +{ + return ksm_mode == KSM_MODE_ALWAYS; +} + +static int __init setup_ksm_mode(char *str) +{ + int ret = 0; + + if (!str) + goto out; + + if (!strcmp(str, "madvise")) { + ksm_mode = KSM_MODE_MADVISE; + ret = 1; + } else if (!strcmp(str, "always")) { + ksm_mode = KSM_MODE_ALWAYS; + ret = 1; + } + +out: + if (!ret) + pr_warn("ksm_mode= cannot parse, ignored\n"); + + return ret; +} +__setup("ksm_mode=", setup_ksm_mode); +#endif + int ksm_enter(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long *vm_flags) { @@ -2881,6 +2917,35 @@ static void wait_while_offlining(void) static struct kobj_attribute _name##_attr = \ __ATTR(_name, 0644, _name##_show, _name##_store) +#ifdef VM_UNMERGEABLE +static ssize_t mode_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + switch (ksm_mode) { + case KSM_MODE_MADVISE: + return sprintf(buf, "always [madvise]\n"); + case KSM_MODE_ALWAYS: + return sprintf(buf, "[always] madvise\n"); + } + + return sprintf(buf, "always [madvise]\n"); +} + +static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + if (!memcmp("madvise", buf, min(sizeof("madvise")-1, count))) + ksm_mode = KSM_MODE_MADVISE; + else if (!memcmp("always", buf, min(sizeof("always")-1, count))) + ksm_mode = KSM_MODE_ALWAYS; + else + return -EINVAL; + + return count; +} +KSM_ATTR(mode); +#endif + static ssize_t sleep_millisecs_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { diff --git a/mm/memory.c b/mm/memory.c index ab650c21bccd..08f3f92de310 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2994,6 +2994,12 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) update_mmu_cache(vma, vmf->address, vmf->pte); unlock: pte_unmap_unlock(vmf->pte, vmf->ptl); + +#if defined(CONFIG_KSM) && defined(VM_UNMERGEABLE) + if (ksm_mode_always()) + ksm_enter(vma->vm_mm, vma, &vma->vm_flags); +#endif + return ret; release: mem_cgroup_cancel_charge(page, memcg, false); From patchwork Fri May 10 07:21:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Natalenko X-Patchwork-Id: 10938307 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 E985613AD for ; Fri, 10 May 2019 07:21:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D26D428A80 for ; Fri, 10 May 2019 07:21:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6D1628BFC; Fri, 10 May 2019 07:21:41 +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 6689E28A80 for ; Fri, 10 May 2019 07:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59AAE6B026A; Fri, 10 May 2019 03:21:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 522E96B026B; Fri, 10 May 2019 03:21:38 -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 39EAB6B026C; Fri, 10 May 2019 03:21:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 0C5836B026A for ; Fri, 10 May 2019 03:21:38 -0400 (EDT) Received: by mail-qk1-f197.google.com with SMTP id a12so4680840qkb.3 for ; Fri, 10 May 2019 00:21:38 -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=UYXKxPKXPsTybNC4JZhfndIieIgXto0Au/T3tY/gXyg=; b=pnWPnqwnV0EssN1TibGFxLx4ekHgf0wbHAVabCb5bHwcaUi468gk7FjB9jfpdBub/q PHtjE19BO+ySKsHArqVeQguG4I/m8kmpj1l9lxQP64ERghmCor0+dIL3hjLHg7seOIHc saZTIKHm+ds4ZV1GCEl8aTstPHBMoU80DVQeeu6bshzAwXDh/+qLETgbO6bDk9zxQ2FI mMijAbb7FriMv/yq07Ul5mjej9jqc/N742Sw/2VHhsWILrOum8FyH9IIBiGN1iNNwVJ3 vaZMTaGT9AyIBdlHC8iLU8u4WscpcyJ80Ev67aUQZ8NKLSPqjSFYfpXP6hyfL0aNld33 rsCA== 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: APjAAAVlj7Wel7hri7EIpAR0odV4NPPRe+BsRzuRBbB3kSMCTHueSUC4 pFBaSmNMYDeSgyvZJLctu/3HgVE/ZeCpn7+OfQCcqM97dmOk1MO8w2IDr/AlvnfNXnAi9ofsSGx RELYyhZEJZF1ZLDqqoZVThOILvMgN5YOS7aRcBSHS9JRrwiuZP0IFKiK+URPQley48w== X-Received: by 2002:ac8:1671:: with SMTP id x46mr8142681qtk.240.1557472897829; Fri, 10 May 2019 00:21:37 -0700 (PDT) X-Received: by 2002:ac8:1671:: with SMTP id x46mr8142653qtk.240.1557472897209; Fri, 10 May 2019 00:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557472897; cv=none; d=google.com; s=arc-20160816; b=U27kWFEEcGQZFk5D7I8/os0iZq1i1LXECATQor1w7AH/u60qGHP0If8xUV293zYbJv /syEHhlldhKAkh7AUkdxTJxvINmaRro+g2vseKsMR6MZBFJEet7dQ1ok/ifATfPgXUFD pzp+e0P6TpDfunQoy/R4RJlLBgjVI971NjtPGqEtHFosxg6h806gJngJo0nqlUMzxonq qD6Swr0/VQC6yElbo1sSTcDUXqkWtOvsqtGJa3hswAP6Yy/J4keGaI7b7kbnFPTm0tBJ cQcAfHaPdQ42kIOpI5TvXGxytUVT7aILXG65mvGwPYbJDP37ZtgAevD6C/18w2JNodtw NmYg== 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=UYXKxPKXPsTybNC4JZhfndIieIgXto0Au/T3tY/gXyg=; b=BqQTRu/9Y/DwptajCOM6RSr4cbwO9Y/TH897zMye1XnYmu3TeNwyUi3G2pfaiZ0Ism IHw/blYGkz9Kr5wOsTfiXb7RAihaludjHjxo02EFKia8HYQnScCz9xyGhxF/amr4/q+G ntI+KsrEBNZ+MCwP6PRK9MnWc1mQwRJ0DWG3iu39qX+iyCW2IIsLpoWBjaydPsL9VA2/ V8xKV8oppjcftO9v9E6+ZVeIYqW+r82ES3mhxrNes15TjQUL423qppUg03ka0xViyOSx Tsmk6vC63km3PvzRzbAug1NcaQIj6sBBzLhEoifmv840LegA+YVSbkZppz54Y4N5x57t 3asQ== 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 y12sor3533473qve.24.2019.05.10.00.21.37 for (Google Transport Security); Fri, 10 May 2019 00:21:37 -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: APXvYqxw5WeE0e1Tl0rCWVbYdCmPx9jVnpRz2LqMlAgWX6iwo8mnCouCMFYdDyqwFsbfVQdq2npsFA== X-Received: by 2002:a0c:b907:: with SMTP id u7mr7761329qvf.189.1557472896947; Fri, 10 May 2019 00:21:36 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id b19sm2308808qkk.51.2019.05.10.00.21.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 May 2019 00:21:36 -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 , linux-mm@kvack.org Subject: [PATCH RFC 4/4] mm/ksm: add automerging documentation Date: Fri, 10 May 2019 09:21:25 +0200 Message-Id: <20190510072125.18059-5-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190510072125.18059-1-oleksandr@redhat.com> References: <20190510072125.18059-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 KSM "always" mode kernel cmdline option as well as corresponding sysfs knob. Signed-off-by: Oleksandr Natalenko --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ Documentation/admin-guide/mm/ksm.rst | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2b8ee90bb644..510766a3fa05 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2008,6 +2008,13 @@ 0: force disabled 1: force enabled + ksm_mode= + [KNL] + Format: [madvise|always] + Default: madvise + Can be used to control the default behavior of the system + with respect to merging anonymous memory. + kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs. Default is 0 (don't ignore, but inject #GP) diff --git a/Documentation/admin-guide/mm/ksm.rst b/Documentation/admin-guide/mm/ksm.rst index 9303786632d1..9af730640da7 100644 --- a/Documentation/admin-guide/mm/ksm.rst +++ b/Documentation/admin-guide/mm/ksm.rst @@ -78,6 +78,13 @@ 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: +mode + * set madvise to deduplicate only madvised memory + * set always to allow deduplicating all the anonymous memory + (applies to newly allocated memory only) + + Default: madvise (maintains old behaviour) + pages_to_scan how many pages to scan before ksmd goes to sleep e.g. ``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``.