Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1901906imm; Thu, 20 Sep 2018 04:53:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaE/q03E+uJxoO69+XAijMKdwHN2BINsiUGxMktTmgpLIPLWljC/KQRDUUVpE3V/ULxIKZf X-Received: by 2002:a63:ea49:: with SMTP id l9-v6mr36625999pgk.427.1537444408352; Thu, 20 Sep 2018 04:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537444408; cv=none; d=google.com; s=arc-20160816; b=oke/yV1iGqUv5te0vrswRBIRRcBw68hjHbBxz9pYW6BIc4f/Msv94ZR9Bp9ZafsJGb tZ0AtpKsjecCRRP7f2FVmqD41kD6x5F2eAzr/j6oROSvOtzBkKNBfaIXTdJb2NbsgLyU s5Fa9G/tgfguuoPzQbBgfYkK01u9+LGZLclsZzaVRY+Y8XPa0zFLcOfroUgh5nG7ToJC Jv2grwfrVRuznLBYs/cwPmLJIu5Q/JxBymMVr3ainiJ0bmMtZq7PPeebSqlSgWpR0wbn pIQvfufYIqkEEKxEsVQ8kkAbTHYIYvYJ7qIXSjVpwJQw5v0VGaguq1gYgDCrcMaBzXOp uWXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hwpdATpvxWQMxRdtNtDgfrk1I10H2ji0HEqs0CTYLOY=; b=wUDBn60cYgK1AJlIqYXb6MER+UMigRzMkL8sE3gOa4+2uSz+QLP7iIwJgHWRJZe9mS zQ6s7SLA9xbGTR77zmg27c9PU07S+aMufmdmf5VKRXa+q7168W0UMHj3tZbVjNOdnI8r 8Y4kjH02HE85jndB7RASBPZSpROdMi3HemZf0Vj7eV3jgCxeC1csh+Cf2mjyYikAnRu7 5mlHgNzgrHa3JIEbhRr8Rn89dW5TtaM8cLE44CMR2a8MzmqXYT41Z90/NzMTcYE1kZJ3 uc3c7zCYUQnbWDa73I1lc6Ubh315wXaVkKQ5/WABBJjvfWn3rk0sFgg0YyBVbLfXmjzb 4LNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vTrxoxdu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h187-v6si26861625pfb.62.2018.09.20.04.53.11; Thu, 20 Sep 2018 04:53:28 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vTrxoxdu; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387481AbeITRek (ORCPT + 99 others); Thu, 20 Sep 2018 13:34:40 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:33570 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbeITRek (ORCPT ); Thu, 20 Sep 2018 13:34:40 -0400 Received: by mail-vk1-f193.google.com with SMTP id m125-v6so1825485vka.0 for ; Thu, 20 Sep 2018 04:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hwpdATpvxWQMxRdtNtDgfrk1I10H2ji0HEqs0CTYLOY=; b=vTrxoxduBydy2hQhAD/bSvhbUJPdPLcrcQ6WXc3HPgFnS70wfnaR3R3lcziMNPeeKO IwhZ7Y9EvcEZUVsoWI66Oy7n6NwC0GRWLD5104wPSErfwObNFgaXoyorvt26nDKyYoZy Q/vPRkNaMBQTUlpC5qbO2rlJWOT/vHjVy15dWUz/GQSyFmvGP/JCLRji636HsFWxchZd a9RqCGueFA/IqZVtGmxpsSQhYuLpWhqqCjd22D40ITEQh3gFmFq5D4dI+XdTqTegXHSi Qf/O1TrvtCeDsk4Ps7/JZzRWk6cI8FgTSULSVQ2CC8oa+wiyAcSzz4RUQ1/bZ6O2Jexr UePw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hwpdATpvxWQMxRdtNtDgfrk1I10H2ji0HEqs0CTYLOY=; b=IkLNfKYAK4Wq2Qwsyk4viZuqAFrF3UQrNOxQcu/SVnzqnzjt/DmRnIDR0yrsyImH0+ d7sLdEFNB37QZVBXoS4S5wqikIPPLo4E/lLORgn0yeZKRm5YIAJbhyrZAaRZZrHxzPz4 Imh8/kwofp1UvCI7WMJuNbxDwqR54XHwHD2/JH+06oHWrHZmkcXmsSFMyBLNfo8AUwMi 3hKkWWj/VYLbp5OwpC8f/eDz2H+D0sKgpf+QtlVe/Su2xTk7VaapDjPqKa5fdrP4Br3M Gk2R9BPAs/Chx5F8V+I/CpnJeKJ3QkWZIhat/IkRxl48i1iE5LifnOzFX6T+d8TTVy3w M3VA== X-Gm-Message-State: APzg51Asjm37XAaSiLoZf6xz56elVJvmGWSRT8qLvABKpfXxVrFcmflA B+KOxIxWraMk/u6nZmRSIhOLPAbxtkahTANVVOU= X-Received: by 2002:a1f:b989:: with SMTP id j131-v6mr10303458vkf.69.1537444291925; Thu, 20 Sep 2018 04:51:31 -0700 (PDT) MIME-Version: 1.0 References: <20180916153237.GC15699@rapoport-lnx> <20180917043724.GA12866@rapoport-lnx> <20180917145936.GA20945@rapoport-lnx> In-Reply-To: <20180917145936.GA20945@rapoport-lnx> From: Pintu Kumar Date: Thu, 20 Sep 2018 17:21:20 +0530 Message-ID: Subject: Re: KSM not working in 4.9 Kernel To: rppt@linux.vnet.ibm.com Cc: open list , Russell King - ARM Linux , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Thank you so much for all your reply so far. I have few more doubts to understand the output from ksm sysfs. Device: Hikey620 - ARM64 - Linux 4.9.20 With HUGE page enabled: CONFIG_TRANSPARENT_HUGEPAGE=y CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y # CONFIG_TRANSPARENT_HUGEPAGE_MADVISE is not set Currently, I get this output, when I run below program with ksm: ~ # grep -H '' /sys/kernel/mm/ksm/* /sys/kernel/mm/ksm/full_scans:29 /sys/kernel/mm/ksm/page_comparisons:39584 /sys/kernel/mm/ksm/pages_hashed:11672 /sys/kernel/mm/ksm/pages_scanned:21766 /sys/kernel/mm/ksm/pages_shared:3 /sys/kernel/mm/ksm/pages_sharing:10097 /sys/kernel/mm/ksm/pages_to_scan:200 /sys/kernel/mm/ksm/pages_unshared:53 /sys/kernel/mm/ksm/pages_volatile:1 /sys/kernel/mm/ksm/run:0 /sys/kernel/mm/ksm/sleep_millisecs:1000 --------------------------- int main(int argc, char *argv[]) { int i, n, size, ret; char *buffer; void *addr; n = 100; size = 100 * getpagesize(); for (i = 0; i < n; i++) { buffer = (char *)malloc(size); memset(buffer, 0xff, size); madvise(buffer, size, MADV_MERGEABLE); if (ret < 0) { fprintf(stderr, "malloc madvise failed: ret: %d, reason: %s\n", ret, strerror(errno)); } usleep(500); } printf("Done....press ^C\n"); pause(); return 0; } Note: madvise() system call is not failing here, as mentioned earlier. I guess the page is aligned with getpagesize(). Then I do this to invoke ksm: # echo 1 > /sys/kernel/mm/ksm/run # ./malloc-test.out & # sleep 5 # echo 0 > /sys/kernel/mm/ksm/run # Also, the anon pages in the system shows like this: BEFORE: ------------- ~ # cat /proc/meminfo | grep -i anon Active(anon): 40740 kB Inactive(anon): 0 kB AnonPages: 40760 kB AnonHugePages: 0 kB AFTER MERGING: -------------------------- ~ # cat /proc/meminfo | grep -i anon Active(anon): 440 kB Inactive(anon): 0 kB AnonPages: 188 kB AnonHugePages: 0 kB I want to understand the KSM output w.r.t to the above program, and cross-check if the output is correct. Can someone help me to understand it? As of now, what I understood is that: - I am allocating around 400KB of memory 100 times. That is: 100 * 100 * 4K = 10000 pages (which are all with similar content). - Output says: 10097 page_sharing happened. - Pages currently shared is: 3 - So total pages are: 10097 + 3 = 10100 I could not understand from where the additional 100 pages came from? Also, why some pages are shown as: pages_unshared ? What can I interpret from this? And, what does it mean by: pages_volatile:1 ? Basically, I wanted to understand, is there any problem with the above output, or it is fine. If it is fine, how to prove it? Thanks, Pintu On Mon, Sep 17, 2018 at 8:29 PM Mike Rapoport wrote: > > On Mon, Sep 17, 2018 at 05:25:27PM +0530, Pintu Kumar wrote: > > On Mon, Sep 17, 2018 at 11:46 AM Pintu Kumar wrote: > > > > > But still no effect. > > > > > And I checked LTP test cases. It almost doing the same thing. > > > > > > > > > > I observed that [ksmd] thread is not waking up at all. > > > > > I gave some print inside it, but I could never saw that prints coming. > > > > > I could not find it running either in top command during the operation. > > > > > Is there anything needs to be done, to wakw up ksmd? > > > > > I already set: echo 1 > /sys/kernel/mm/ksm. > > > > > > > > It should be echo 1 > /sys/kernel/mm/ksm/run > > > > > > > > > > Oh yes, sorry for the typo. > > > I tried the same, but still ksm is not getting invoked. > > > Could someone confirm if KSM was working in 4.9 kernel? > > > > > > > Ok, it's working now. I have to explicitly stop the ksm thread to see > > the statistics. > > Also there was some internal patch that was setting vm_flags to > > VM_MERGABLE thus causing ksm_advise call to return. > > > > # echo 1 > /sys/kernel/mm/ksm/run > > # ./malloc-test.out & > > # echo 0 > /sys/kernel/mm/ksm/run > > > > ~ # grep -H '' /sys/kernel/mm/ksm/* > > /sys/kernel/mm/ksm/full_scans:105 > > /sys/kernel/mm/ksm/pages_shared:1 > > /sys/kernel/mm/ksm/pages_sharing:999 > > /sys/kernel/mm/ksm/pages_to_scan:100 > > /sys/kernel/mm/ksm/pages_unshared:0 > > /sys/kernel/mm/ksm/pages_volatile:0 > > /sys/kernel/mm/ksm/run:0 > > /sys/kernel/mm/ksm/sleep_millisecs:20 > > > > > > However, I have one doubt. > > Is the above data correct, for the below program? > > You have 1 shared page and 999 additional references to that page > > > int main(int argc, char *argv[]) > > { > > int i, n, size, ret; > > char *buffer; > > void *addr; > > > > n = 10; > > size = 100 * getpagesize(); > > for (i = 0; i < n; i++) { > > buffer = (char *)malloc(size); > > memset(buffer, 0xff, size); > > madvise(buffer, size, MADV_MERGEABLE);o > > This madvise() call should fail because buffer won't be page aligned > > > addr = mmap(NULL, size, > > PROT_READ | PROT_EXEC | PROT_WRITE, > > MAP_PRIVATE | MAP_ANONYMOUS, > > -1, 0); > > memset(addr, 0xff, size); > > ret = madvise(addr, size, MADV_MERGEABLE); > > if (ret < 0) { > > fprintf(stderr, "madvise failed: ret: %d, > > reason: %s\n", ret, strerror(errno)); > > } > > usleep(500); > > } > > printf("Done....press ^C\n"); > > > > pause(); > > > > return 0; > > } > > > > > > Thanks, > > Pintu > > > > -- > Sincerely yours, > Mike. >