@@ -1001,11 +1001,11 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1001
1001
struct zswap_entry * entry , * dupentry ;
1002
1002
struct crypto_comp * tfm ;
1003
1003
int ret ;
1004
- unsigned int dlen = PAGE_SIZE , len ;
1004
+ unsigned int hlen , dlen = PAGE_SIZE ;
1005
1005
unsigned long handle , value ;
1006
1006
char * buf ;
1007
1007
u8 * src , * dst ;
1008
- struct zswap_header * zhdr ;
1008
+ struct zswap_header zhdr = { . swpentry = swp_entry ( type , offset ) } ;
1009
1009
1010
1010
if (!zswap_enabled || !tree ) {
1011
1011
ret = - ENODEV ;
@@ -1063,8 +1063,8 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1063
1063
}
1064
1064
1065
1065
/* store */
1066
- len = dlen + sizeof (struct zswap_header ) ;
1067
- ret = zpool_malloc (entry -> pool -> zpool , len ,
1066
+ hlen = zpool_evictable ( entry -> pool -> zpool ) ? sizeof (zhdr ) : 0 ;
1067
+ ret = zpool_malloc (entry -> pool -> zpool , hlen + dlen ,
1068
1068
__GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM ,
1069
1069
& handle );
1070
1070
if (ret == - ENOSPC ) {
@@ -1075,10 +1075,9 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1075
1075
zswap_reject_alloc_fail ++ ;
1076
1076
goto put_dstmem ;
1077
1077
}
1078
- zhdr = zpool_map_handle (entry -> pool -> zpool , handle , ZPOOL_MM_RW );
1079
- zhdr -> swpentry = swp_entry (type , offset );
1080
- buf = (u8 * )(zhdr + 1 );
1081
- memcpy (buf , dst , dlen );
1078
+ buf = zpool_map_handle (entry -> pool -> zpool , handle , ZPOOL_MM_RW );
1079
+ memcpy (buf , & zhdr , hlen );
1080
+ memcpy (buf + hlen , dst , dlen );
1082
1081
zpool_unmap_handle (entry -> pool -> zpool , handle );
1083
1082
put_cpu_var (zswap_dstmem );
1084
1083
@@ -1149,8 +1148,9 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset,
1149
1148
1150
1149
/* decompress */
1151
1150
dlen = PAGE_SIZE ;
1152
- src = (u8 * )zpool_map_handle (entry -> pool -> zpool , entry -> handle ,
1153
- ZPOOL_MM_RO ) + sizeof (struct zswap_header );
1151
+ src = zpool_map_handle (entry -> pool -> zpool , entry -> handle , ZPOOL_MM_RO );
1152
+ if (zpool_evictable (entry -> pool -> zpool ))
1153
+ src += sizeof (struct zswap_header );
1154
1154
dst = kmap_atomic (page );
1155
1155
tfm = * get_cpu_ptr (entry -> pool -> tfm );
1156
1156
ret = crypto_comp_decompress (tfm , src , entry -> length , dst , & dlen );
0 commit comments