Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1575384

Re: memfill

From Minchan Kim <minchan@kernel.org>
Newsgroups linux.kernel
Subject Re: memfill
Date 2017-02-07 06:10 +0100
Message-ID <t86cp-6K6-3@gated-at.bofh.it> (permalink)
References <t7wLE-AL-9@gated-at.bofh.it> <t7SMb-6cu-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Hi Matthew,

On Mon, Feb 06, 2017 at 06:49:02AM -0800, Matthew Wilcox wrote:
> 
> [adding linux-arch to see if anyone there wants to do an optimised
> version of memfill for their CPU]
> 
> On Mon, Feb 06, 2017 at 12:16:44AM +0900, Minchan Kim wrote:
> > +static inline void zram_fill_page(char *ptr, unsigned long len,
> > +					unsigned long value)
> > +{
> > +	int i;
> > +	unsigned long *page = (unsigned long *)ptr;
> > +
> > +	WARN_ON_ONCE(!IS_ALIGNED(len, sizeof(unsigned long)));
> > +
> > +	if (likely(value == 0)) {
> > +		memset(ptr, 0, len);
> > +	} else {
> > +		for (i = 0; i < len / sizeof(*page); i++)
> > +			page[i] = value;
> > +	}
> > +}
> 
> I would suggest:
> 
> #ifndef __HAVE_ARCH_MEMFILL
> /** 
>  * memfill - Fill a region of memory with the given value
>  * @s: Pointer to the start of the region.
>  * @v: The word to fill the region with.
>  * @n: The size of the region.
>  * 
>  * Differs from memset() in that it fills with an unsigned long instead of 
>  * a byte.  The pointer and the size must be aligned to unsigned long.
>  */
> void memfill(unsigned long *s, unsigned long v, size_t n)
> {
> 	WARN_ON_ONCE(!IS_ALIGNED(n, sizeof(v)));
> 
> 	if (likely(v == 0)) {
> 		memset(s, 0, n);
> 	} else {
> 		while (n) {
> 			*s++ = v;
> 			n -= sizeof(v);
> 		}
> 	}
> }
> EXPORT_SYMBOL(memfill);
> #endif
> 
> (I would also suggest this move to lib/string.c and architectures be
> given the opportunity to provide an optimised version of memfill).

Thanks for suggestion, Matthew!

However, I want to mention zram's performance wouldn't be sensitive
for that function because non-zero memfill would be rare.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4] zram: extend zero pages to same element pages Minchan Kim <minchan@kernel.org> - 2017-02-05 16:20 +0100
  memfill Matthew Wilcox <willy@infradead.org> - 2017-02-06 15:50 +0100
    Re: memfill zhouxianrong <zhouxianrong@huawei.com> - 2017-02-07 03:50 +0100
    Re: memfill Minchan Kim <minchan@kernel.org> - 2017-02-07 06:10 +0100
    Re: memfill David Howells <dhowells@redhat.com> - 2017-02-07 10:50 +0100
      Re: memfill Matthew Wilcox <willy@infradead.org> - 2017-02-07 18:30 +0100
        Re: memfill David Howells <dhowells@redhat.com> - 2017-02-07 18:40 +0100
          Re: memfill Matthew Wilcox <willy@infradead.org> - 2017-02-07 20:10 +0100
    Re: memfill James Bottomley <James.Bottomley@HansenPartnership.com> - 2017-02-07 20:10 +0100
      Re: memfill James Bottomley <James.Bottomley@HansenPartnership.com> - 2017-02-08 22:10 +0100
        Re: memfill Matthew Wilcox <willy@infradead.org> - 2017-02-08 23:00 +0100
      Re: memfill Matthew Wilcox <willy@infradead.org> - 2017-02-08 23:10 +0100
  Re: [PATCH v4] zram: extend zero pages to same element pages Minchan Kim <minchan@kernel.org> - 2017-02-07 08:00 +0100

csiph-web