Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6355463yba; Tue, 14 May 2019 06:19:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVlKg11dh+YMvbgjdJrsmllBpHrPUsJxi6+kTkQO6pNMlHVNseYImb83pfiCVkawR0jx1T X-Received: by 2002:a63:5012:: with SMTP id e18mr37263217pgb.383.1557839958611; Tue, 14 May 2019 06:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557839958; cv=none; d=google.com; s=arc-20160816; b=OZsgF62Hu0Q+AnIxFSZheMa12i1L84SH0l+l/VhgT1Lrie9H5RCd/QjOVFpNOvbbav oNQ+7wE6DIyRTv+fGuc9qLpen8RLMDjpDYAfPoOCAMu6kOcssERp4BajBLRpVMFQv8sh phvhP17ruX+m1ja+yosxLwXH36/vH3w5cXRhwQnbrrL6qtFnYHqyI3jpU9pr6sW84729 32X8O0fbrQqVMm3CO9eZptKdzQ0z6O3+BA4U/z75qt5Z8anDwD6q6yIAAuKvpEk8wlRx RNthoiOeIgxm9VMGf3ltyrtUuf9cCfAYGLRZhLZq6iQswxCuguH8hN2ENwaR5fli3G/y 6b1g== 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 :message-id:date:subject:cc:to:from; bh=XOfzdfS9JDTS2x5DGGI6S8ITgh1lhmu7AKXviivuHlM=; b=l5xqRwus0GCW2h2tlRk34ORxBxR0skGnNhCOotE7+W1ba6Cmg+U6tYK8PxK7+ogEqq tZaWWXmLQ+a8n6NOmX3sJrdv7/dDBNQfAcSeXoW7JhQOL1iF4VfHNO7Qd5rFWa5l5+y5 cFxjKqnYpX/VZWc1becyTp2aIM1MMJlDP29y0X4KujtNO3qVVF0sMUM1/U54p5ALB29g zX/hHNIzBhDwYq8/IBoQdpeeACv1LtfxQMtolPaI+2HMgGTXLp6KN+qCIGXSzoqZJG1G YUsxevMCptX5GZiHTS2pq5TAykX6KhPxWlywqOkosjtGWE4o/sWlusKPJ/jmUdQClflG i7tg== 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 b62si17590778pga.51.2019.05.14.06.19.03; Tue, 14 May 2019 06:19:18 -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 S1726272AbfENNRB (ORCPT + 99 others); Tue, 14 May 2019 09:17:01 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51110 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbfENNQ6 (ORCPT ); Tue, 14 May 2019 09:16:58 -0400 Received: by mail-wm1-f66.google.com with SMTP id f204so2858055wme.0 for ; Tue, 14 May 2019 06:16:57 -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:mime-version :content-transfer-encoding; bh=XOfzdfS9JDTS2x5DGGI6S8ITgh1lhmu7AKXviivuHlM=; b=gso/FRID7p+BCbQFGmwg9f6soFny5MCF+FRJxVG9xHrpA6xZ4WuAYtabpcsBwLf1xu b8pPmTBYp5bzYJAPSmBOwCFLFTazrhErp1hTe+eKKqY/7dV9JHbWrwoYh5FK/5ZBBxJa 3WWJ5JsOcVtlXHOFkJ7Ya2GWItUHrZXihsulbMgHtZFGxZY640AJg5Gb5T+0VmlMlEpj vnXOQNLM9ObHKtCKKtPmXYJk2RNnSdvvUkYqWh3q/A7rMNC271U6ZoWHYCrGwZKwhISn lAtmJDOjMFAWQjXhkZzMc4ykMMSYJ17lNmUJ+wip5jNYNpxP/wkOlVNTHjN4tIk0jUk7 IxAA== X-Gm-Message-State: APjAAAVJ4TXB7TDK29zk+/RDHCyr5WbewmQwmOhwUPauvBW92dC47L7k CGcNEFYDnb98o8lGL9orHzpfmDgOxao3DA== X-Received: by 2002:a1c:f310:: with SMTP id q16mr20319455wmq.102.1557839816601; Tue, 14 May 2019 06:16:56 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id l12sm3350136wmj.0.2019.05.14.06.16.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 May 2019 06:16:55 -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 0/4] mm/ksm: add option to automerge VMAs Date: Tue, 14 May 2019 15:16:50 +0200 Message-Id: <20190514131654.25463-1-oleksandr@redhat.com> X-Mailer: git-send-email 2.21.0 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 By default, 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. Instead, lets implement a sysfs knob, which allows marking VMAs as mergeable. This can be used manually on some task in question or by some small userspace helper daemon. The knob is named "force_madvise", and it is write-only. It accepts a PID to act on. To mark the VMAs as mergeable, use: # echo PID > /sys/kernel/mm/ksm/force_madvise To unmerge all the VMAs, use the same approach, prepending the PID with the "minus" sign: # echo -PID > /sys/kernel/mm/ksm/force_madvise This patchset is based on earlier Timofey's submission [1], but it doesn't use dedicated kthread to walk through the list of tasks/VMAs. Instead, it is up to userspace to traverse all the tasks in /proc if needed. The previous suggestion [2] was based on amending do_anonymous_page() handler to implement fully automatic mode, but this approach was incorrect due to improper locking and not desired due to excessive complexity. The current approach just implements minimal interface and leaves the decision on how and when to act to userspace. Thanks. [1] https://lore.kernel.org/patchwork/patch/1012142/ [2] http://lkml.iu.edu/hypermail/linux/kernel/1905.1/02417.html Oleksandr Natalenko (4): mm/ksm: introduce ksm_enter() helper mm/ksm: introduce ksm_leave() helper mm/ksm: introduce force_madvise knob mm/ksm: add force merging/unmerging documentation Documentation/admin-guide/mm/ksm.rst | 11 ++ mm/ksm.c | 160 +++++++++++++++++++++------ 2 files changed, 137 insertions(+), 34 deletions(-) -- 2.21.0