Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1303794ybi; Sun, 16 Jun 2019 01:59:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqypsTgX3iIA6fc2XLVCiIfqHSw99V78ixUT/5nOaET0Q6RZ4dHG3wDfReKO6kWN1MCFSc6m X-Received: by 2002:aa7:8c0f:: with SMTP id c15mr81821501pfd.113.1560675579035; Sun, 16 Jun 2019 01:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560675579; cv=none; d=google.com; s=arc-20160816; b=OjCRjdU8jXqhU8p/g0x5Jr8WfnHtGf8xvM1CFdM6uwB+Yir5ksF594d1gs2/nXnE73 lg8Lz78nj4vbg6Rp9mso/FKHUGq8VKLCn9TiP0kOTQ9wFM3AsXK5QeWV8G7zYGGq+YZc Vqcz7NX5P0F0DW0si8NPLdBSFZAYh8pcGkPT5LOLXEzii5BWRK/bpt44ySRotAWJ+KnS r6Xh2QChC0wuZ6jC/6BXcq5rIAQqSNA9kDJwyPt751Lff7s/qRYFZhAf8l534xqqTpp0 6R4G2wJ4jx6dFfVGnXhRQo0L1Quckx/cVRUqV7tFJUuP+8lXqXlHlJpsS82nMMAI7FG8 3Dyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hjjZi7hVawe1O5sE3agHwwCxgHKG18ng7v/8qT0V/18=; b=wcrfp8Y+IU/AXtBPGx+7e5P/Ml/ZigCIYdGk2Lj1y1jsMetZCqnqBaB6LkpofOvBay ycHONq+EMmib/8J2ASPdN3H0N1zsOK4CTxi7QxgtNQE4x235jqZSVsZuEm3GLXuZLW9f lNQ/8F0xWQThG8MC7VpUGAhmniZi7yQ2GQSYhMj/RB04PY+LFiXFXYI8M4yoLhrkUpAO uJj5ToDrK1vJBCcTOSjP2c+bRpd+C5WaCkbo2eMiqZkzl/J7iZ9PJQwKs0GJFTKc3weZ 0ABwRFXT9um/TMfpJgub6HcTDHhp8rGREOhqw8jkdvcRGOoe27dBKM78LMIwQqHSjN0R sDYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si7357411pgs.215.2019.06.16.01.59.24; Sun, 16 Jun 2019 01:59:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727208AbfFPI6y (ORCPT + 99 others); Sun, 16 Jun 2019 04:58:54 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37702 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbfFPI6q (ORCPT ); Sun, 16 Jun 2019 04:58:46 -0400 Received: by mail-wr1-f68.google.com with SMTP id v14so6688277wrr.4 for ; Sun, 16 Jun 2019 01:58:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hjjZi7hVawe1O5sE3agHwwCxgHKG18ng7v/8qT0V/18=; b=eyWxOWtoV8GDuAYao0F/YtIphqgqy9hT+kTnLUZAJd2q5cYyJSeAE+A3L1KRc1sQkZ fwBSfuKO/0CS0fMuIPEcW2sRDgovnptmulBYnzy62kJGvhUYsou6tcDWjoz0BUdtpiId z5zsbN5g347uD46LaCfnnZ3E913g633YrX/SKKqFC0jwNk6W0hlX43yyDBkv6r01naO3 PkLfanpuAFnD6hWKgCjTiWL7MzceruZHYkubkqUcARTQQG17o3nVyATJkXwgK9EtnObD +pt9Ptta3nfqpNBrlnRzAUnpNlV8jUL+2HTRazkt1xFFIW/IJDdTOSq4YAJml6SATUp4 e+dw== X-Gm-Message-State: APjAAAU5dt6truCNdxibyGRHpa02DYiVEAk938GHwMUz6qBHH5l/gg22 uer4C6Aw40nylo/WPx9DlX5H/g== X-Received: by 2002:a5d:56c1:: with SMTP id m1mr56928115wrw.26.1560675525088; Sun, 16 Jun 2019 01:58:45 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id c4sm3173448wrb.68.2019.06.16.01.58.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 01:58:44 -0700 (PDT) From: Oleksandr Natalenko To: Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org Subject: [PATCH NOTFORMERGE 5/5] mm/madvise: allow KSM hints for remote API Date: Sun, 16 Jun 2019 10:58:35 +0200 Message-Id: <20190616085835.953-6-oleksandr@redhat.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190616085835.953-1-oleksandr@redhat.com> References: <20190616085835.953-1-oleksandr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/ Signed-off-by: Oleksandr Natalenko --- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 84f899b1b6da..e8f9c49794a3 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -991,6 +991,8 @@ process_madvise_behavior_valid(int behavior) switch (behavior) { case MADV_COLD: case MADV_PAGEOUT: + case MADV_MERGEABLE: + case MADV_UNMERGEABLE: return true; default: -- 2.22.0