Re: [PATCH] mm: extend zero pages to same element pages for zram

From: Matthew Wilcox
Date: Mon Feb 06 2017 - 09:14:56 EST


On Mon, Feb 06, 2017 at 09:28:18AM +0800, zhouxianrong wrote:
> > > +static inline void zram_fill_page_partial(char *ptr, unsigned int size,
> > > + unsigned long value)
> > > +{
> > > + int i;
> > > + unsigned long *page;
> > > +
> > > + if (likely(value == 0)) {
> > > + memset(ptr, 0, size);
> > > + return;
> > > + }
> > > +
> > > + i = ((unsigned long)ptr) % sizeof(*page);
> > > + if (i) {
> > > + while (i < sizeof(*page)) {
> > > + *ptr++ = (value >> (i * 8)) & 0xff;
> > > + --size;
> > > + ++i;
> > > + }
> > > + }
> > > +
> >
> > I don't think we need this part because block layer works with sector
> > size or multiple times of it so it must be aligned unsigned long.
>
> Minchan and Matthew Wilcox:
>
> 1. right, but users could open /dev/block/zram0 file and do any read operations.

But any such read operation would go through the page cache, so will
be page aligned. Unless they do an O_DIRECT operation, in which case
it must be aligned to block size. Please, try it. I/Os which are not
aligned should be failed long before they reach your driver.