From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D58C4C34031 for ; Wed, 19 Feb 2020 01:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9BB524655 for ; Wed, 19 Feb 2020 01:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582076696; bh=o0k1i8LR+2j+sq5ZUmduCOhaYXaMIshAzdEIiIZWoH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=AO3sJPlth5IKpyv7xQ6A58xlXp325k350OyhXmVJpstFiqixL01lCLHGsWZ04Ekhl B9CoCdr2zmqpUZ6pHhrhoBq9hPWLvkCoxLyf/dTMRYOWy27v3Pun/QjmWY0DRq0S7z RYPpco2I822bpJDMdrqn5gSlfjpuw2E24r3lhiKY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727944AbgBSBov (ORCPT ); Tue, 18 Feb 2020 20:44:51 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34626 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728078AbgBSBou (ORCPT ); Tue, 18 Feb 2020 20:44:50 -0500 Received: by mail-pf1-f196.google.com with SMTP id i6so11656831pfc.1; Tue, 18 Feb 2020 17:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1scw6AX0QdFLv3QhbE20elC6cFG9ULuE6N92X44brJw=; b=H6fLGsg2j4PmTw3SItfmAmcqvkvaIG3s5xSjQFvJtLfGEss07bBJGio+X/KLry8eDb 3of397TcAuTYOfo72or2nw1YG+7ZRabRZNJpup3S4vrdMouvHDJOTAv6Pxc7GfNR0Bwe blIMw1KBPy7QVkpINhoirPf72oM2gT3KRqDJ4YFwQtsaY0WYzYeZ2i6ro5LfpAfsbXPj osVnUSsQr/acQmJOrN/DtYiXzUJDqzDhSUt2tc3mJLCPD3K4QUzagSsD/XXGVNUtMVp+ hXXTA2+BOdSzcH+RoGXH7VosRcAp00hFbxtoGwNnyTeNo8o0XKOhn0m58Z/P6g33gfXW B/8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=1scw6AX0QdFLv3QhbE20elC6cFG9ULuE6N92X44brJw=; b=EA4B+v5SJ/GZpTSrNjY8vlpg6WkYGlj8PmpA9+V9/30h/MTrqBSD/Rayx6hFj9+Pwf mjFWMIR94Z4SRRhJqIIndFQbmYr1jl6Eh+f6YpQ9TKqgTQaDuBB6n1ZWte4wvvUodVFk jz7a96ZIZ7jrRKGFAsgwHYd86lO9i1a5kfPzjWAdKAEiovgoivWR8KHZGmnhn/RKbzTL 1XUZEAdcoeFlf0L6wGMIApcWZypNIy83pkZJUo1Grw4AniKddzPURLOJ4Cdqr4jDIXKc odWIgEVpaJNdG6FrixXUtQ6WzQPRidZhvpFYNHH7omDNDISx5ElWddVXpZScPl1Tjuxd FhUg== X-Gm-Message-State: APjAAAUEgsCq/XZJYiCEogssgISH0wYzVG2bBVhvrMTXlyfvVZb+UHwM zHB3DjxnWsTHoX0DfxEgxxU= X-Google-Smtp-Source: APXvYqyz3X7WGwptvOEiJxwSNXqqwTYv3ZYeA8KT5pni5GmwVfEADCKS6SJfoeyphY2Axu5WL8Tqpg== X-Received: by 2002:a63:5818:: with SMTP id m24mr25869925pgb.358.1582076690066; Tue, 18 Feb 2020 17:44:50 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id t186sm221192pgd.26.2020.02.18.17.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 17:44:48 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , sj38.park@gmail.com, alexander.h.duyck@linux.intel.com, Jann Horn , Minchan Kim , SeongJae Park Subject: [PATCH v6 7/7] mm/madvise: allow KSM hints for remote API Date: Tue, 18 Feb 2020 17:44:33 -0800 Message-Id: <20200219014433.88424-8-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200219014433.88424-1-minchan@kernel.org> References: <20200219014433.88424-1-minchan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-api-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org From: Oleksandr Natalenko It all began with the fact that KSM works only on memory that is marked by madvise(). And the only way to get around that is to either: * use LD_PRELOAD; or * patch the kernel with something like UKSM or PKSM. (i skip ptrace can of worms here intentionally) To overcome this restriction, lets employ a new remote madvise API. This can be used by some small userspace helper daemon that will do auto-KSM job for us. I think of two major consumers of remote KSM hints: * hosts, that run containers, especially similar ones and especially in a trusted environment, sharing the same runtime like Node.js; * heavy applications, that can be run in multiple instances, not limited to opensource ones like Firefox, but also those that cannot be modified since they are binary-only and, maybe, statically linked. Speaking of statistics, more numbers can be found in the very first submission, that is related to this one [1]. For my current setup with two Firefox instances I get 100 to 200 MiB saved for the second instance depending on the amount of tabs. 1 FF instance with 15 tabs: $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc 410 2 FF instances, second one has 12 tabs (all the tabs are different): $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc 592 At the very moment I do not have specific numbers for containerised workload, but those should be comparable in case the containers share similar/same runtime. [1] https://lore.kernel.org/patchwork/patch/1012142/ Reviewed-by: SeongJae Park Signed-off-by: Oleksandr Natalenko Signed-off-by: Minchan Kim --- mm/madvise.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index c55a18fe71f9..b97c7e1a5cab 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1005,6 +1005,10 @@ process_madvise_behavior_valid(int behavior) switch (behavior) { case MADV_COLD: case MADV_PAGEOUT: +#ifdef CONFIG_KSM + case MADV_MERGEABLE: + case MADV_UNMERGEABLE: +#endif return true; default: return false; -- 2.25.0.265.gbab2e86ba0-goog