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=-2.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 C8A79C433E1 for ; Fri, 12 Jun 2020 13:55:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7255F20792 for ; Fri, 12 Jun 2020 13:55:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AGm49oXO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7255F20792 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CA19D8D00C3; Fri, 12 Jun 2020 09:55:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C524B8D00A0; Fri, 12 Jun 2020 09:55:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1A1A8D00C3; Fri, 12 Jun 2020 09:55:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 956A58D00A0 for ; Fri, 12 Jun 2020 09:55:48 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4881B181ABE8D for ; Fri, 12 Jun 2020 13:55:48 +0000 (UTC) X-FDA: 76920707976.16.pain25_351136326ddd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 08B131006A272 for ; Fri, 12 Jun 2020 13:55:47 +0000 (UTC) X-HE-Tag: pain25_351136326ddd X-Filterd-Recvd-Size: 7335 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Fri, 12 Jun 2020 13:55:46 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id r18so4160081pgk.11 for ; Fri, 12 Jun 2020 06:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jjd0AuUqDMS+kg7RMfFuNDT5WMCpvxZwxODMYSMGb1M=; b=AGm49oXOJa5zvbGQSmCtPupmqX/vK0ZW8yO+FtbKQdYZhs/qHaUS/YrDhFOr2Ohk2C vmm3wEH/np8fZhGqc4XNfrMnILSw+UvGZdh/wynEj63vaoMLII/YBTTwfnYG1oMkd4yi mTsaj9JZb9qzBuD1CwqYPNRWvT82p5TKFWey09Jyp+fc0NjpoYrOH9XkEmy19ojS8tJB bcm/JOqSpb+/aYnPpOBvKGsvTRzsD7FLRL86I+HhWCdtQgLN/F4Jn6yCLgjwWIuUGWh6 EpgBun44z05r0/yWcQIBB+1WyCZrI2OfsoCxeHxH3rFDK+tZWE1El3KgmYVY7xldognU KF0Q== 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=jjd0AuUqDMS+kg7RMfFuNDT5WMCpvxZwxODMYSMGb1M=; b=PNMgMn3n5voGtfO7dAYp/AtKjupbF9UKD6dh9xgazpSTfeOxNIiskpibZKLPRJNtHI LAdxw3jQQTXkC+xQfs2h7oLELLae+uepf0oP8vFqntmu7i+bya2KshdXz0LIo3leWXZO G4pbx5PqT79e3QvT1gRZn2JucsTrt4dsv1KSMGTPNGTsmhGk4vHc/Lh0t2MfkIhlRpQ5 fhyajJnqLPgxrslzK2xK1LTRz6e0UqHHnt/T+Y4V7DkRYq38wsjE6ikK7C+Q5azy0QVH aA9T1yqZ1XePjH2zSVK6k+wD/apPHol/LJ6q8k6BYfFXalbGXkdukiVJ1lcSSXDfy4l0 DfWQ== X-Gm-Message-State: AOAM531LxBStuqEYQpN2LRCLQvFRJsOdz1XW8MEzQy9uEJQqz25XXQ8V XaTZ4eocpfCjw279vRIHyWM= X-Google-Smtp-Source: ABdhPJxZsluvfDXjcLYcixbYMCGaCMI0iW8Tje9KJtl2C3rbqpPHE3nY5bBWjfZrbopCFK5js/mV7w== X-Received: by 2002:a63:7707:: with SMTP id s7mr10832085pgc.295.1591970145638; Fri, 12 Jun 2020 06:55:45 -0700 (PDT) Received: from localhost ([49.207.50.185]) by smtp.gmail.com with ESMTPSA id e127sm6617854pfe.45.2020.06.12.06.55.44 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Jun 2020 06:55:44 -0700 (PDT) Date: Fri, 12 Jun 2020 19:25:38 +0530 From: afzal mohammed To: Arnd Bergmann Cc: Russell King - ARM Linux admin , Linus Walleij , "linux-kernel@vger.kernel.org" , Linux-MM , Linux ARM , Nicolas Pitre , Catalin Marinas , Will Deacon Subject: Re: [RFC 1/3] lib: copy_{from,to}_user using gup & kmap_atomic() Message-ID: <20200612135538.GA13399@afzalpc> References: <9e1de19f35e2d5e1d115c9ec3b7c3284b4a4e077.1591885760.git.afzal.mohd.ma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) X-Rspamd-Queue-Id: 08B131006A272 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, On Fri, Jun 12, 2020 at 02:02:13PM +0200, Arnd Bergmann wrote: > On Fri, Jun 12, 2020 at 12:18 PM afzal mohammed wrote: > > Roughly a one-third drop in performance. Disabling highmem improves > > performance only slightly. > There are probably some things that can be done to optimize it, > but I guess most of the overhead is from the page table operations > and cannot be avoided. Ingo's series did a follow_page() first, then as a fallback did it invoke get_user_pages(), i will try that way as well. Yes, i too feel get_user_pages_fast() path is the most time consuming, will instrument & check. > What was the exact 'dd' command you used, in particular the block size? > Note that by default, 'dd' will request 512 bytes at a time, so you usually > only access a single page. It would be interesting to see the overhead with > other typical or extreme block sizes, e.g. '1', '64', '4K', '64K' or '1M'. It was the default(512), more test results follows (in MB/s), 512 1K 4K 16K 32K 64K 1M w/o series 30 46 89 95 90 85 65 w/ series 22 36 72 79 78 75 61 perf drop 26% 21% 19% 16% 13% 12% 6% Hmm, results ain't that bad :) > If you want to drill down into where exactly the overhead is (i.e. > get_user_pages or kmap_atomic, or something different), using > 'perf record dd ..', and 'perf report' may be helpful. Let me dig deeper & try to find out where the major overhead and try to figure out ways to reduce it. One reason to disable highmem & test (results mentioned earlier) was to make kmap_atomic() very lightweight, that was not making much difference, around 3% only. > > +static int copy_chunk_from_user(unsigned long from, int len, void *arg) > > +{ > > + unsigned long *to_ptr = arg, to = *to_ptr; > > + > > + memcpy((void *) to, (void *) from, len); > > + *to_ptr += len; > > + return 0; > > +} > > + > > +static int copy_chunk_to_user(unsigned long to, int len, void *arg) > > +{ > > + unsigned long *from_ptr = arg, from = *from_ptr; > > + > > + memcpy((void *) to, (void *) from, len); > > + *from_ptr += len; > > + return 0; > > +} > > Will gcc optimize away the indirect function call and inline everything? > If not, that would be a small part of the overhead. i think not, based on objdump, i will make these & wherever other places possible inline & see the difference. > > + num_pages = DIV_ROUND_UP((unsigned long)from + n, PAGE_SIZE) - > > + (unsigned long)from / PAGE_SIZE; > > Make sure this doesn't turn into actual division operations but uses shifts. > It might even be clearer here to open-code the shift operation so readers > can see what this is meant to compile into. Okay > > > + pages = kmalloc_array(num_pages, sizeof(*pages), GFP_KERNEL | __GFP_ZERO); > > + if (!pages) > > + goto end; > > Another micro-optimization may be to avoid the kmalloc for the common case, > e.g. anything with "num_pages <= 64", using an array on the stack. Okay > > + ret = get_user_pages_fast((unsigned long)from, num_pages, 0, pages); > > + if (ret < 0) > > + goto free_pages; > > + > > + if (ret != num_pages) { > > + num_pages = ret; > > + goto put_pages; > > + } > > I think this is technically incorrect: if get_user_pages_fast() only > gets some of the > pages, you should continue with the short buffer and return the number > of remaining > bytes rather than not copying anything. I think you did that correctly > for a failed > kmap_atomic(), but this has to use the same logic. yes, will fix that. Regards afzal