Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6012757yba; Mon, 13 May 2019 23:31:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzpubyHT55yQPzgWNs2S12AaX4cvo5e95Ppvh27s9Puv930JVTdfw3IVXCfK77JVEq3K8g X-Received: by 2002:a63:fc55:: with SMTP id r21mr35950369pgk.441.1557815515628; Mon, 13 May 2019 23:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557815515; cv=none; d=google.com; s=arc-20160816; b=WnqMAMVOirSi6wNZHFRJ92c16T1+j90Vll+ZsYLMbbyqXIt/YrpitxqjsrycCJbEnI +JN4I41wWwXgm5cj6NO/n820UPl4lNYwkdBCjYp5M2JMfo9oBrBlzJNeV/b8dtNi7dGM W3KwuxuI+Z1cEEpZXUcCes0iDIkIL56TL9bNyycarQV3fK69GDvHXLhf6z1KUsdooGDn POEWoI0x95X4gU7FKUMzcyWjDw5lQpGook98+ibKQq3rMzeMVNJr8Dgw50qwb62dDYGr rJcNnfV325V9U0qePpbnGAZ7R9IoGU5ZHW89DaFNEKmqmh8wxcAX8CCOhxs9KYM4Dl2r FHCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mgFD/HBmqD9tbHso2Ft8IrmU0HCter766u/5lDK5MD4=; b=StkPc8kGGG0gS8m52QPTXgibbLq47aEap7omlTFpR59djNHjwK7wMqMm6qHBwsmiQC PfXo5j+itFfxbbG+i10MWSY2mIEe8F7N8FcAYYTGYAcdlfKSvYhj6K02CXCmWSk4IfQl W1NQPLT6q9iV2wmIJ4ggspDnGUjlgxlnz9JdkKWYuP5b8scEsRJYzLvGi9L+ElpO3WSa 4CIoqCjp2eVdQCAWn0vLihH3M2eGUzS8c3QPxBqg4kFJhdb9t9kxsIPDNbHCOUTXeuV8 5lGngUQy8UjDo0Pe3BCd8ywGLSgSK36rcLG5/03y4tF0lncmUtKRVP0lde5NXJnILM3X uJBw== 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 m63si2683390pld.421.2019.05.13.23.31.39; Mon, 13 May 2019 23:31:55 -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 S1726248AbfENGas (ORCPT + 99 others); Tue, 14 May 2019 02:30:48 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:39014 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbfENGar (ORCPT ); Tue, 14 May 2019 02:30:47 -0400 Received: by mail-qt1-f193.google.com with SMTP id y42so2961081qtk.6 for ; Mon, 13 May 2019 23:30:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mgFD/HBmqD9tbHso2Ft8IrmU0HCter766u/5lDK5MD4=; b=gmZ+nK/L1S2bq89wiQ5Hy2tKJOZRQRY4Lqfb4IcaUxFBXGiga6Ir/41FTMFgY2fD07 6NUfgfvShoVfoOX0/uW6PiwFNtLJBPJoJjfG4qkQ+MiE4T6hRLOLfHPyCG1qMnYHNfUv yelVGaxPEDehyTDFvSBOyO8ORlkob9oTUjmJMIIQ8IdC6NcoQT/SN5S38vbFHRpjq3zQ POjIP+h+Tl6AncXLglfF+Xfkm6P0u5sgzq4EYI2+HKb1bUO52ngSv0aYVIMLibffl2OE evan7xmTbZeaFeRB3u1woPl59wtceLo8FEiLa/gpy/WRE0fAKTGIcdMy3i5+a0W4iGa3 1Cvg== X-Gm-Message-State: APjAAAXohvw1Xb/R9XgjarhJ+8RME8czbpykIWZw/J229KE/+SS74Zq2 m7+YjrO9lliY1S/8UWYcAZk2sw== X-Received: by 2002:ac8:8ad:: with SMTP id v42mr27107649qth.337.1557815446620; Mon, 13 May 2019 23:30:46 -0700 (PDT) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id a51sm6532064qta.85.2019.05.13.23.30.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 May 2019 23:30:45 -0700 (PDT) Date: Tue, 14 May 2019 08:30:43 +0200 From: Oleksandr Natalenko To: Kirill Tkhai Cc: linux-kernel@vger.kernel.org, Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Timofey Titovets , Aaron Tomlin , linux-mm@kvack.org Subject: Re: [PATCH RFC 0/4] mm/ksm: add option to automerge VMAs Message-ID: <20190514063043.ojhsb6d3ohxx4wur@butterfly.localdomain> References: <20190510072125.18059-1-oleksandr@redhat.com> <36a71f93-5a32-b154-b01d-2a420bca2679@virtuozzo.com> <20190513113314.lddxv4kv5ajjldae@butterfly.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. On Mon, May 13, 2019 at 03:37:56PM +0300, Kirill Tkhai wrote: > > Yes, I get your point. But the intention is to avoid another hacky trick > > (LD_PRELOAD), thus *something* should *preferably* be done on the > > kernel level instead. > > I don't think so. Does userspace hack introduce some overhead? It does not > look so. Why should we think about mergeable VMAs in page fault handler?! > This is the last thing we want to think in page fault handler. > > Also, there is difficult synchronization in page fault handlers, and it's > easy to make a mistake. So, there is a mistake in [3/4], and you call > ksm_enter() with mmap_sem read locked, while normal way is to call it > with write lock (see madvise_need_mmap_write()). > > So, let's don't touch this path. Small optimization for unlikely case will > introduce problems in optimization for likely case in the future. Yup, you're right, I've missed the fact that write lock is needed there. Re-vamping locking there is not my intention, so lets find another solution. > > Also, just for the sake of another piece of stats here: > > > > $ echo "$(cat /sys/kernel/mm/ksm/pages_sharing) * 4 / 1024" | bc > > 526 > > This all requires attentive analysis. The number looks pretty big for me. > What are the pages you get merged there? This may be just zero pages, > you have identical. > > E.g., your browser want to work fast. It introduces smart schemes, > and preallocates many pages in background (mmap + write 1 byte to a page), > so in further it save some time (no page fault + alloc), when page is > really needed. But your change merges these pages and kills this > optimization. Sounds not good, does this? > > I think, we should not think we know and predict better than application > writers, what they want from kernel. Let's people decide themselves > in dependence of their workload. The only exception is some buggy > or old applications, which impossible to change, so force madvise > workaround may help. But only in case there are really such applications... > > I'd researched what pages you have duplicated in these 526 MB. Maybe > you find, no action is required or a report to userspace application > to use madvise is needed. OK, I agree, this is a good argument to move decision to userspace. > > 2) what kinds of opt-out we should maintain? Like, what if force_madvise > > is called, but the task doesn't want some VMAs to be merged? This will > > required new flag anyway, it seems. And should there be another > > write-only file to unmerge everything forcibly for specific task? > > For example, > > Merge: > #echo $task > /sys/kernel/mm/ksm/force_madvise Immediate question: what should be actually done on this? I see 2 options: 1) mark all VMAs as mergeable + set some flag for mmap() to mark all further allocations as mergeable as well; 2) just mark all the VMAs as mergeable; userspace can call this periodically to mark new VMAs. My prediction is that 2) is less destructive, and the decision is preserved predominantly to userspace, thus it would be a desired option. > Unmerge: > #echo -$task > /sys/kernel/mm/ksm/force_madvise Okay. > In case of task don't want to merge some VMA, we just should skip it at all. This way we lose some flexibility, IMO, but I get you point. Thanks. -- Best regards, Oleksandr Natalenko (post-factum) Senior Software Maintenance Engineer